Unix Technical Forum

"insert on existing update" in MS SQL Server?

This is a discussion on "insert on existing update" in MS SQL Server? within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello I used to work in a Sybase database environment. When I had to insert/ update records in the ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 01:15 PM
Bart op de grote markt
 
Posts: n/a
Default "insert on existing update" in MS SQL Server?

Hello

I used to work in a Sybase database environment. When I had to insert/
update records in the database, I always used "insert on existing
update", in this way, you didn't have to check whether a record
already existed (avoid errors) and you were always sure that after
running the scripts, the last version was in the database.

Now I'm looking for the same functionality in MS SQL Server, asked a
few people, but nobody knows about such an option.
Does anybody here knows the SQL Server counterpart of "insert on
existing skip/update"? If this doesn't exist, this is a minus for
MS .

Greetz,

Bart

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 01:15 PM
Serge Rielau
 
Posts: n/a
Default Re: "insert on existing update" in MS SQL Server?

Bart op de grote markt wrote:
> Hello
>
> I used to work in a Sybase database environment. When I had to insert/
> update records in the database, I always used "insert on existing
> update", in this way, you didn't have to check whether a record
> already existed (avoid errors) and you were always sure that after
> running the scripts, the last version was in the database.
>
> Now I'm looking for the same functionality in MS SQL Server, asked a
> few people, but nobody knows about such an option.
> Does anybody here knows the SQL Server counterpart of "insert on
> existing skip/update"? If this doesn't exist, this is a minus for
> MS .

In ANSI/SQL it's called a MERGE statement.
In SQL Server I'd do an UPDATE FROM, if no row found follow up with an
INSERT.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 01:15 PM
Erland Sommarskog
 
Posts: n/a
Default Re: "insert on existing update" in MS SQL Server?

Bart op de grote markt (bartwarnez@freegates.be) writes:
> I used to work in a Sybase database environment. When I had to insert/
> update records in the database, I always used "insert on existing
> update", in this way, you didn't have to check whether a record
> already existed (avoid errors) and you were always sure that after
> running the scripts, the last version was in the database.
>
> Now I'm looking for the same functionality in MS SQL Server, asked a
> few people, but nobody knows about such an option.
> Does anybody here knows the SQL Server counterpart of "insert on
> existing skip/update"? If this doesn't exist, this is a minus for
> MS .


I'm afraid that you will have to chalk up one minus for MS SQL Server.

You will have to do:

UPDATE ...

INSERT ...
SELECT ...
WHERE NOT EXISTS (....)


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 01:16 PM
Bart op de grote markt
 
Posts: n/a
Default Re: "insert on existing update" in MS SQL Server?

Ok, thank you all for the replies! It's a pity but well :-). If MS
reads this post: hello MS, you know what to do next.


Grtz,

Bart

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-01-2008, 01:16 PM
Alex Kuznetsov
 
Posts: n/a
Default Re: "insert on existing update" in MS SQL Server?

On Feb 6, 7:28 am, "Bart op de grote markt" <bartwar...@freegates.be>
wrote:
> Hello
>
> I used to work in a Sybase database environment. When I had to insert/
> update records in the database, I always used "insert on existing
> update", in this way, you didn't have to check whether a record
> already existed (avoid errors) and you were always sure that after
> running the scripts, the last version was in the database.
>
> Now I'm looking for the same functionality in MS SQL Server, asked a
> few people, but nobody knows about such an option.
> Does anybody here knows the SQL Server counterpart of "insert on
> existing skip/update"? If this doesn't exist, this is a minus for
> MS .
>
> Greetz,
>
> Bart


Also look up "Mimicking MERGE Statement in SQL Server 2005 ":

http://sqlserver-tips.blogspot.com/2...nt-in-sql.html

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:18 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com