If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > smart insert or update

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-17-04, 05:24
tgkprog tgkprog is offline
Registered User
 
Join Date: Oct 2003
Location: blr india
Posts: 2
smart insert or update

how come there aint no commant like insertUpdate - that takes the Pk cols, then the Pk values, then the other cols and the other vals - and if it finds a existing row with the Pk values then updates that with the other values else inserts a new row. For tables with a few columns this would be great.

Some thing like this:
insertUpdate (pkColName1, pkColName2, pkColName3, ...), (pkColValue1, pkColValue2, pkColValue3, ...) ( genColName1, genColName2, ...)
(genColValue1, genColValue2, ... )
Reply With Quote
  #2 (permalink)  
Old 01-17-04, 06:40
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: smart insert or update

Oracle 9i has a MERGE statement that does something quite like that, though you have to specify the conditions rather than rely on PK constraints (which would be nicer in some ways).
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 01-17-04, 06:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Re: smart insert or update

Quote:
Originally posted by tgkprog
how come there aint no commant like insertUpdate
there is in mysql

INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name
SET col_name=(expression | DEFAULT), ...
[ ON DUPLICATE KEY UPDATE col_name=expression, ... ]
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 01-17-04, 07:43
tgkprog tgkprog is offline
Registered User
 
Join Date: Oct 2003
Location: blr india
Posts: 2
nice ! anything for MS SQL Server?
Reply With Quote
  #5 (permalink)  
Old 01-17-04, 08:08
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
not that i'm aware of

use T-SQL to see if the PK exists first, and UPDATE or INSERT accordingly
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On