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
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Logging ROWS not inserted due to failure in passin

Author  Topic 

bsethi24
Starting Member

25 Posts

Posted - 2012-03-12 : 09:36:21
Dear All,

Hi! I am searching a solution to log all the rows those are not inserted in a table due to failure in passing Primary and/or any UNIQUE Constraint implemented on this table.


For example,

We have a table named "Customer" with CUSTOMERID as Primary Key and "CUSTOMERID" and "MOBILENO" as UNIQUE Constraint.

Now if we insert a row in this table with CUSTOMERID that already exists then SQL Server does not allow us to insert such record(s).

OR

If we try to insert a row with CUSTOMERID and MOBILENO that already exists again SQL SERVER does not allow us to do the same.


Hence, I need to LOG such records with their Failure Reason (i.e. due to Primary Key failure or UNIQUE key failure) in another table?


How can I achieve the same? Is there more than one solution for such problem & what is the best one to achieve the same??

Thanks & Regards,
BSethi24
   

- Advertisement -