Hello guys,
I have one table Products and a second Products_audit with two columns User and Date. I need to have trigger which performs following actions:
When anybody will modify data in Products, I need trigger to insert the User's name and Date of inserting into the Products_audit in appropriate columns. I wrote following:
When I try to insert data into Products I get error:
Server: Msg 515, Level 16, State 2, Procedure Super1, Line 6
Cannot insert the value NULL into column 'Discontinued', table 'Teachdb.dbo.Pr oducts_audit'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I don't understand why it points out on 'Discontinued' column ? Note: before trigger was created I didn't face with that issue when I inserted data.
I have one table Products and a second Products_audit with two columns User and Date. I need to have trigger which performs following actions:
When anybody will modify data in Products, I need trigger to insert the User's name and Date of inserting into the Products_audit in appropriate columns. I wrote following:
Code:
CREATE TRIGGER Super1 ON Products AFTER UPDATE, INSERT AS BEGIN SET NOCOUNT ON; INSERT INTO Products_audit (Date, [User]) SELECT suser_sname(),getdate() FROM Products END
Server: Msg 515, Level 16, State 2, Procedure Super1, Line 6
Cannot insert the value NULL into column 'Discontinued', table 'Teachdb.dbo.Pr oducts_audit'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I don't understand why it points out on 'Discontinued' column ? Note: before trigger was created I didn't face with that issue when I inserted data.
Comment