September 7, 2014 at 9:15 am
Dear experts,
Im new to sql server and got stuck in the following .
Ive a stored procedure A which has data has a result of split function from a column X of a main table B.
Ive to insert the values of the stored procedure A into a new table called C and want to join with Table B (COLUMNPK, NEWCOLUMN (varcharmax),null)
when i insert values into table C on NEWCOLUMN i get an error .
code:
insert into Table B (NEWCOLUMN)
exec dbo.spA
error:
Cannot insert NULL into the column 'COLUMNPK', the table B does not allow Null .
The statement has been terminated.
But, im actually inserting the values in NEWCOLUMN and not the other one s per the error message.
steps tried out:
1. tried changing the data type of NEWCOLUMN from NULL to NOT NULL, but the update statement also failed.
2. tools-->options--> table& designer--> unchecked the prevent save changes
also did not help.
Request your help and guidance here.
Regards,
Srikanth Baskaran
September 7, 2014 at 9:26 am
srikanth.baskaran (9/7/2014)
Dear experts,Im new to sql server and got stuck in the following .
Ive a stored procedure A which has data has a result of split function from a column X of a main table B.
Ive to insert the values of the stored procedure A into a new table called C and want to join with Table B (COLUMNPK, NEWCOLUMN (varcharmax),null)
when i insert values into table C on NEWCOLUMN i get an error .
code:
insert into Table B (NEWCOLUMN)
exec dbo.spA
error:
Cannot insert NULL into the column 'COLUMNPK', the table B does not allow Null .
The statement has been terminated.
But, im actually inserting the values in NEWCOLUMN and not the other one s per the error message.
steps tried out:
1. tried changing the data type of NEWCOLUMN from NULL to NOT NULL, but the update statement also failed.
2. tools-->options--> table& designer--> unchecked the prevent save changes
also did not help.
Request your help and guidance here.
Regards,
Srikanth Baskaran
Quick question, is the offending pk column an identity column or where does that value come from?
😎
September 7, 2014 at 9:37 am
hello,
Thanks for your reply.
Iven't made the pk column a identity column yet, but set it as a primary key.
Im inserting the values of stored procedure in to the other column ir NEWCOLUMN.
Regards
Srikanth Baskaran
September 7, 2014 at 10:15 am
The problem is that when you insert the value into NEWCOLUMN, you're inserting NULLS and default values in the other columns to complete the row.
If you have a PK constraint on a column, it can't receive null values. You should either insert the correct values on the PK column or set the identity property to ON on that column.
September 8, 2014 at 8:16 am
When I get stuck with some error like this, I like to see what I am inserting into the table.
So I would do an
exec dbo.spA --(without the insert)
and visually see the data being returned
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply