Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with records that fail to be inserted

Status
Not open for further replies.

Katy44

Technical User
Dec 12, 2003
723
GB
Is there a way to work with records that fail to be inserted into a table?

I have a command:

insert into Table1
(select * from Table2)

but Table1 has more constraints on it, so some records will fail (this is what I want to happen). However, I would ideally like to be able to identify these records, and the constraint they failed on.

I know there is other ways of doing it, for example selecting stuff in 2 that is not in 1, but for a few different reasons this would be the best way to do it. Is it possible?
 
No, you can't do an insert and then say <for those records that fail> <do something else>. For a start, in a single insert, if one row fails then the whole insert is rolled back and nothing will be inserted.

I would suggest you only insert rows that will succedd (using a query to filter valid records) and then use another query to get the rows that would have failed.

--James
 
OK, I'll do that, thank you for confirming that it is not possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top