A SQL statement typically used to `UPDATE` records when they exist and `INSERT` them when they do not.

learn more… | top users | synonyms

1
vote
0answers
40 views

RETURNING syntax with multiple columns

Again, another question related to the answer of the one there: Insert with OUTPUT correlated to sub query table So I ended up with this query, written for SQL Server: CREATE TABLE tempIDs ( ...
4
votes
1answer
214 views

A clarification of MERGE best practices

I just wanted to ask a clarification about something on the MSDN from the "Optimizing MERGE Statement Performance" page. I am working with a data warehouse that takes in records from many different ...
0
votes
3answers
497 views

SQL Server - Copy data from one database to another - identical tables, new identity values needed

Here's the thing, I have been running identical copies of my website for two different geographical regions. The site now supports multi-currency pricing so I want to merge both sites together. All ...
3
votes
1answer
84 views

Does MERGE updates when not needed?

In SQL Server 2012, Does a merge statement like this : WHEN MATCHED THEN update SET A.len = B.len updates a row even if A.len equals to B.len ? Or does the SQL SERVER knows to ignore this ...
0
votes
0answers
31 views

Merge Similar Schema from one MySQL DB to Another

I have two databases (db1 and db2). db2 has all tables from db1 but not necessarily the same columns. I want to move any missing columns in db2 from tables in db1 but keep the rest unchanged. ...
2
votes
2answers
154 views

Merging two backups form a postgresql database

I have a kind of big postgresql database and two backup files (each uncompressed dump file ~56 mb) representing 2 states of the data in time. 1st state - backup from a couple days ago 2nd state - ...
1
vote
0answers
45 views

How to merge rows based on how much data they have?

I am cleaning data and I formed a table something like this: file | product | color | product_id --------------------------------------------- one.csv pipe blue null ...
1
vote
1answer
87 views

Merge Fields into one Row with a Query

I am working with Microsoft Office Professional Plus 2010. What I am trying to figure out is how to merge all characters for each DOMAIN field into one row, for example: Q01 ...
0
votes
0answers
51 views

Merging Large Database Tables Quickly

So I found this other post; Merge multiple tables in a database And that's the general idea, but at an insanely large scale. Anyway -- Over the years, Our site has adapted and three different things ...
0
votes
1answer
381 views

Problem using merge into a remote table over dblink

I'm attempting to perform a merge into a remote table, let's say on server A (over a dblink), using a local table on server B. Source and target databases are both on Oracle 10.2.0.3. We already have ...
0
votes
0answers
321 views

Oracle merge query vs correlated update

I have a query which updates a table with data from another table. The current query is written as a correlated update with an exists clause to remove unnecessary rows. The problem is since both of ...
0
votes
4answers
838 views

How do I delete only related records in a multi-key MERGE in SQL Server?

Suppose you have something like this: Source table (variable): Values ( LeftId INT NOT NULL, RightId INT NOT NULL, CustomValue varchar(100) NULL ) Target table: Mapping ( LeftId INT NOT ...
3
votes
2answers
622 views

Can I optimize this MERGE statement?

I am attempting a single column merge between two tables. The first table (VisitorSession) has 40,000,000 rows. The second (ShoppingCart) has 9,000,000 rows. In my development environment, the query ...
1
vote
1answer
91 views

Help with best practice of merging databases

Bad news, our website server (Windows 2003) crashed because of dead RAID controller. Luckily few hours later our backup server was up and website was live again. Hopefully tomorrow our original ...
0
votes
0answers
52 views

Transfer tables from multiple servers into one single server [duplicate]

I have to migrate similar tables present in multiple different servers (30+) into our new server using SSIS package. What would be the right approach towards this? I was successfully able to transfer ...
1
vote
1answer
176 views

Merge Statement + Replication difference for SQL Server 2012

We have a SSIS package that will pull from a source database and run a merge statement to put the data into a "Master" database. (Eventually the "Master" database will be the source of truth, but we ...
1
vote
1answer
108 views

Equivalent of MRG_MYISAM in databases other than MySQL? [closed]

Does anyone know if other database have something equivalent to MRG_MYISAM (aka the MERGE table type/storage engine)? I know about fragmenting, but this is not quite the same AFAIK. We're using ...
1
vote
2answers
82 views

getting error when i use merge statement

I am using sql 2008 r2. when i use merge statement i am gettig error when i execute following code: merge products as trgt using updatedproducts as src on (trgt.productid = src.productid) ...
11
votes
1answer
3k views

MERGE a subset of the target table

I am trying to use a MERGE statement to insert or delete rows from a table, but I only want to act on a subset of those rows. The documentation for MERGE has a pretty strongly worded warning: It ...
1
vote
1answer
154 views

Is there a way to write intelligent queries against a merge table in MySQL that represents a bunch of tables partitioned by date?

I have a set of MySQL tables that are partitioned by date, with a merge table representing all of them. For the query I am writing, the results are joined by date, so rows in table A_2012-12-05 will ...
4
votes
1answer
465 views

MERGE with OUTPUT doesn't seem to be doing the right thing

I'm adding a foreign key to a table, and removing any rows that violate the FK, copying them into a ModifiedTable_invalid table. As part of the script, I've got the following MERGE command: MERGE ...
2
votes
2answers
843 views

Merge two records in the same table, keeping foreign key relationships intact for both

I have a table, called SITES, that has three columns, lets say it looks like this: ID Name Path 1 Google http://www.google.com/ 2 Microsoft http://www.microsoft.com/ I also have ...
2
votes
1answer
407 views

oracle merge operation hangs (or loops); query tuner claims it's a cartesian product operation

I have a Merge query (open to better suggestions) that seems to cause the server to hang. (I'm not sure what it's doing, but it pegs the CPU and never completes) When I run it through the query ...
3
votes
0answers
84 views

Once in a while synchronization of the independently updated mysql databases problem

I have a production database and a test database running on MySQL with MyISAM and InnoDB tables, which are updated independently. The Production database is updated by system and sometimes by a user. ...
7
votes
3answers
3k views

SQL Server 2008 merge statement deadlocking itself

I have the following procedure (SQL Server 2008r2): create procedure usp_SaveCompanyUserData @companyId bigint, @userId bigint, @dataTable tt_CoUserdata readonly as begin set ...
7
votes
2answers
671 views

Merge replication fails on executing query

My merge replication was working fine this morning. Since an hour or 2 ago, my synchronisation status windows keeps showing this message: Thread id 3108 will wait for 15 second(s) before retrying the ...
5
votes
2answers
373 views

How to use merge hints to isolate complex queries in SQL Server

I can understand that if I join individual queries that are "individually fast" the combination may become slow because the default execution plan may be non-optimal. However when I know the number ...
6
votes
1answer
1k views

What are my locking options for a Merge statement?

I have a stored procedure that performs a MERGE statement. It seems like it locks the whole table by default when performing the merge. I'm calling this stored procedure inside of a transaction ...
1
vote
0answers
182 views

What overhead is there if I MERGE row by row?

I have a target table of about 2000 rows and I want to be able to MERGE (with HOLDLOCK) about 5-10 rows at a time into the target table. The target table doesn't get used heavily, with only 1-2 users ...
0
votes
1answer
104 views

Re-subscribing to a merge publication after edits made offline

Hypothetical Question - To help scenario planning. Let's say I have a 2008 R2 Merge Publication with 5 active subscribers. The publication is deleted and all subscriptions are removed. A week or so ...
5
votes
1answer
1k views

Oracle's Merge v. Select->Update/Insert

What is the faster statement? A MERGE or Select->Update/Insert depending on if it returns a value? I'm trying to optimize a database, but I haven't found any speed tests comparing the two. I found ...