I have a stored procedure to insert a record into two tables.
First I have it insert into tableA, and then into tableB.
I am a little confused because if the insert into tableA fails, I expect it to error out and not run the next statement. But that doesn't seem to be the case..
If an exception happens it still run the statements below it?...
BEGIN
INSERT INTO TABLEA (Counter) VALUES (1989); -- duplicate error!
INSERT INTO TABLEB (Counter) VALUES (2010);
END
The error I get is:
Violation of PRIMARY KEY constraint 'PK_TABLEA'. Cannot insert duplicate key in object 'dbo.TABLEA'. The duplicate key value is (1989). The statement has been terminated.
I do get an error when I call this stored procedure in my C# console application though. That's why I'm confused as to why its raising the exception.. but continuing with the next statements...