Reputation: 21
I am trying to do an insert but it is giving an error stating that credits cannot be null but I am not providing null. Attached Screenshot
Code: Insert into [dbo].[Course] values (12,'Java',1,1,1);
Error: Msg 515, Level 16, State 2, Procedure trgAfterInsert, Line 31 Cannot insert the value NULL into column 'Credits', table 'DemoCollege.dbo.Course'; column does not allow nulls. INSERT fails. The statement has been terminated.
Trigger:
Create trigger trgAfterInsert2 ON [dbo].[Course]
After Insert
AS
Declare @cid int;
Declare @cname nvarchar(50);
Select @cid = i.CourseID from inserted i;
Select @cname = i.Title from inserted i;
Insert into dbo.CourseTemp values (@cid, @cname);
Print 'After insert trigger fired';
GO
Upvotes: 2
Views: 1829
Reputation: 13960
Just provide the columns where you want to insert the values.
Insert into [dbo].[Course](ColName1, ColName2, ColName3, ColName4, etc..) values (12,'Java',1,1,1);
Most probably you're missing a col in the middle
Upvotes: 1
Reputation: 1972
There's an insert trigger on the table & that's where the error is being generated from. There must be some logic in that is converting the provided credit value to a null value somehow.
Upvotes: 2