473,785 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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

Feb 6 '07 #1
4 13203
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
Feb 6 '07 #2
Bart op de grote markt (ba********@fre egates.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, es****@sommarsk og.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
Feb 6 '07 #3
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

Feb 7 '07 #4
On Feb 6, 7:28 am, "Bart op de grote markt" <bartwar...@fre egates.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

Feb 7 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11122
by: lawrence | last post by:
Google can't find me a good example of how to use the "if exists" syntax in MySql. Is it right that to use it this way: INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk") I want to insert into a table but only if the table exists. How does one, in general, from PHP, test for the existence of a table, without getting an error message?
2
2817
by: sm | last post by:
How to "Insert" (not append) new text segment to an existing text file? Assume that we have text file as shown below; Elvis Sofia Kylix BCB--> How to insert here? Atten BuilderX Roma
4
2074
by: hao | last post by:
Hi, all When I use ASP to insert an record to a database, I got some errors and can not insert any value with Chinese Char. The only way I can do that is use "rst1.Addnew...rst1.update". Anyone know why? thx
3
4935
by: Kevin Pedersen | last post by:
Hello, I am using an editable datagrid. After I save the changes the datagrid shows the old values. I've read the posts about the Page_Load and not binding the datagrid each time. The SQL that is being sent to the database is correct and the changes are eventually being made. If I refresh the page after the update then the new values appear. I noticed that when I put a breakpoint in my update handler everything works fine. When I take...
3
37815
by: Ed | last post by:
Hi, I want to load data to a table in Sql Server from a dataset table in my vb.net app using a dataAdapter. I know how to do this as follows (my question is to see if I can reduce the amount of code below): .... Dim DA As SqlDataAdapter = New SqlDataAdapter Dim Parm As New SqlParameter ....
20
18388
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've been doing something like delete from foo where name = 'xx'; insert into foo values('xx',1,2,...);
13
3188
by: shankindc | last post by:
Hi, I have a data entry form which opens default values each time the form is open. Requirement is that users can edit existing data in the form. When the form is closed, it shouldnt update the existing record but rather insert a new record. On the Form-Beforeupdate function, I first check if the record already exists (Primary keys exist). Then I wrote a "Insert into" SQL that picks all values from the form and inserts into the backend...
1
1377
jhardman
by: jhardman | last post by:
I know this question deals with a lot of SQL, but I am applying it to ASP, so I think this is the best place for it. When I learned SQL, I saw the "insert" command as very useless. It tries to do so much that it often gives errors, since any part of it wrong generates an error. I always use "addnew" which allows you to add each entry on a new line. Although this may generate errors, you can easily handle the errors or use the error to...
3
1702
by: Twanne | last post by:
Hi, I've got a table called Aerosol and a table called LinkTabel. Now I do an update to a table from an excell sheet, this table is called ExportAerosol. So far so good, the import works perfect. Now when I want to transfer the data from the ExportAerosol table to the Aerosol table I have to make a unique key. I do this by adding a string to another key. Now there is no problem when I update the Aerosol table. It adds the values I...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.