Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert and delete in one statement

Author  Topic 

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-01-02 : 10:03:04
i am creating an insert based on a select statement -- i need to delete the row from the select statment table after it has been inserted

something like

insert into table_insert(value1, value2)
(select table_exclude_id, value1, value2 from table exclude)
delete from table_exclude where table_exclude_id in "the select statement"

can you do this?

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2007-01-02 : 10:07:14
no....but you can put it 2 statements into 1 "transaction" so that either they both work, or neither works.
Go to Top of Page

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-01-02 : 10:16:01
how do you put both statements into one transaction?
Go to Top of Page

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-01-02 : 10:18:16
i tried it with cursors and its really slow

to do the insert on the select with 8k record is a few seconds

to do it with a cursor and the delete and insert takes several minutes
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-02 : 10:24:56
Duplicate question:
[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76925[/url]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -