I have a table with a primary key and a stored procedure I use to insert to that table. I have no control over the stored procedure and cannot change it. Sometimes the procedure returns many records and 1 record with a NULL value for the primary key column. At the moment, the entire batch of new rows fails to insert.
How can I configure my code or the table to fail only on the 1 row with the NULL value, but allow the other rows to be inserted?
Here is some test code:
IF OBJECT_ID('tempdb..#tbl') IS NOT NULL
DROP TABLE #tbl
CREATE TABLE #tbl (
col INT NOT NULL,
CONSTRAINT PK_tbl PRIMARY KEY (col ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = ON, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
SET XACT_ABORT OFF
--Imagine this is the procedure that cannot be edited
insert into #tbl (col) values
(null), (1), (2)
--Ideally, the table would have 1 and 2
select * from #tbl