sql-merge

Oracle Pro*C Bulk Merge of records in C using host arrays degrading performance with increased volume

≡放荡痞女 提交于 2019-12-12 06:31:54
问题 Using Oracle 11g Pro*C in C, I am using host arrays for managing bulk merge into DB table as per following example: merge into TBL_NM A using (select 1 from dual) B on (col1 = to_date(:v,'YYMMDD') and col2 = :v and col3 = :v and col4 = :v) when matched then update set col5 = :v, col2 = col2+ :v, col3 = col3 + :v when not matched then insert (col1, col2, col3, col4, col5, col6, col7, col8) values (to_date(:v,'YYMMDD'),:v,:v,:v,:v,:v,:v,:v) My first Question is: whether this way of bulk merge

SQL merge statements on tables with foreign keys and resolving deadlocks

浪子不回头ぞ 提交于 2019-12-11 11:38:16
问题 I have a couple of MERGE statements that I execute inside a transaction from within ADO.NET code. The first table's Id will be assigned automatic when inserting into the table. The second table does have a Foreign-key constraint, that's why I have this select in my insert statement. The matching is actually based on some natural key because the surrogate keys are not exposed outside the application. The MERGE statements look like these. merge MyTable with (rowlock, updlock) as t using

Unkillable Oracle session waiting on “SQL*Net message from client” event

邮差的信 提交于 2019-12-10 14:21:35
问题 On Oracle 11gR2, I've recently encountered a very interesting situation involving a blocked (but idle!) MERGE statement that hangs on a "SQL*Net message from client" event, causing subsequent, concurrently executed MERGE statements to block on the first statement via "cursor: pin S wait on X" events. In Oracle Enterprise Manager, the following can be observed: This situation turns even more severe, as the above Session-ID 1204 cannot be killed with either: alter system kill session 'sid

Oracle sql MERGE INTO with a single where clause

我是研究僧i 提交于 2019-12-10 11:23:32
问题 I have the following SQL code (this is how much I've got so far): MERGE INTO SCHEMA1.TABLE_1 table1 USING ( SELECT DISTINCT table2.column1, view1.column2 FROM SCHEMA2.TABLE_2 table2 LEFT JOIN SCHEMA2.VIEW_1 view1 ON table2.column2 = view1.column3 ) t2 ON (table1.column3 = t2.column1 ) WHEN MATCHED THEN UPDATE SET table1.column4 = t2.column2; The following is the definition of VIEW_1 : CREATE VIEW SCHEMA_2.VIEW_1 AS (SELECT SCHEMA_2.TABLE_1.COLUMN_1, SCHEMA_2.TABLE_2.COLUMN_1, SCHEMA_2.TABLE_2

T-SQL MERGE Performance in typical publishing context

房东的猫 提交于 2019-12-09 01:45:49
问题 I have situation where a "publisher" application essentially keeps a view model up to date by querying a VERY complex view and then merging the results into a denormalized view model table, using separate insert, update, and delete operations. Now that we have upgraded to SQL 2008 I figured it would be a great time to update these with the SQL MERGE statement. However after writing the query, the subtree cost of the MERGE statement is 1214.54! With the old way, the sum of the Insert/Update

MERGE INTO table containing AUTO_INCREMENT columns

ぃ、小莉子 提交于 2019-12-08 08:19:50
问题 I've declared the following table for use by audit triggers: CREATE TABLE audit_transaction_ids (id IDENTITY PRIMARY KEY, uuid VARCHAR UNIQUE NOT NULL, `time` TIMESTAMP NOT NULL); The trigger will get invoked multiple times in the same transaction. The first time the trigger is invoked, I want it to insert a new row with the current TRANSACTION_ID() and time. The subsequent times the trigger is invoked, I want it to return the existing "id" (I invoke Statement.getGeneratedKeys() to that end)

MERGE INTO table containing AUTO_INCREMENT columns

跟風遠走 提交于 2019-12-06 16:09:39
I've declared the following table for use by audit triggers: CREATE TABLE audit_transaction_ids (id IDENTITY PRIMARY KEY, uuid VARCHAR UNIQUE NOT NULL, `time` TIMESTAMP NOT NULL); The trigger will get invoked multiple times in the same transaction. The first time the trigger is invoked, I want it to insert a new row with the current TRANSACTION_ID() and time. The subsequent times the trigger is invoked, I want it to return the existing "id" (I invoke Statement.getGeneratedKeys() to that end) without altering "uuid" or "time". The current schema seems to have two problems. When I invoke MERGE

Oracle sql MERGE INTO with a single where clause

情到浓时终转凉″ 提交于 2019-12-06 14:03:31
I have the following SQL code (this is how much I've got so far): MERGE INTO SCHEMA1.TABLE_1 table1 USING ( SELECT DISTINCT table2.column1, view1.column2 FROM SCHEMA2.TABLE_2 table2 LEFT JOIN SCHEMA2.VIEW_1 view1 ON table2.column2 = view1.column3 ) t2 ON (table1.column3 = t2.column1 ) WHEN MATCHED THEN UPDATE SET table1.column4 = t2.column2; The following is the definition of VIEW_1 : CREATE VIEW SCHEMA_2.VIEW_1 AS (SELECT SCHEMA_2.TABLE_1.COLUMN_1, SCHEMA_2.TABLE_2.COLUMN_1, SCHEMA_2.TABLE_2.COLUMN_2, SCHEMA_2.TABLE_2.COLUMN_3, SCHEMA_2.TABLE_5.COLUMN_1, SCHEMA_2.TABLE_6.COLUMN_1, SCHEMA_2

Update and Insert When Condition is Matched in TSQL-Merge

こ雲淡風輕ζ 提交于 2019-12-05 20:26:35
I have been trying to Write a Stored Procedure where i can perform UpSert using Merge with the Following Condition If Record is Present then change EndDate of Target to Yesterday's day i.e., Present Day - 1 If Record is not Present then Insert New Record Here is the Table tblEmployee i used in SP CREATE TABLE tblEmployee ( [EmployeeID] [int] IDENTITY(1,1) NOT NULL, [Name] [varchar](10) NOT NULL, [StartDate] [date] NOT NULL, [EndDate] [date] NOT NULL ) Here is my SP which Takes UDTT as Input parameter CREATE PROCEDURE [dbo].[usp_UpsertEmployees] @typeEmployee typeEmployee READONLY -- It has

Is Merge and Merge join same in SQL Server?

余生长醉 提交于 2019-12-05 17:19:09
What is the difference between Merge and a Merge Join in SQL Server? MERGE is a DML statement (data manipulation language). Also called UPSERT (Update-Insert). It tries to match source (table / view / query) to a target (table / updatable view) based on your defined conditions and then based on the matching results it insert/update/delete rows to/in/of the target table. MERGE (Transact-SQL) create table src (i int, j int); create table trg (i int, j int); insert into src values (1,1),(2,2),(3,3); insert into trg values (2,20),(3,30),(4,40); merge into trg using src on src.i = trg.i when not