I have inside a stored procedure:
INSERT INTO SitesCategories(SiteID, CategoryID) VALUES(@SITEID, @TempCId);
This insert could throw exceptions because I have this constraint on the table:
ALTER TABLE dbo.SitesCategories
ADD CONSTRAINT UniqueSiteCategPair
UNIQUE (SiteId,CategoryID);
I made this constraint so that I would not have to check when inserting the uniques of the pairs (@SITEID, @TempCId). But I do not want that an SQl exception is thrown when this gets executed inside the stored procedure. How can I "catch" the exception inside the stored procedure and continue operations inside the procedure ?
BEGIN TRY
INSERT INTO SitesCategories(SiteID, CategoryID) VALUES(@SITEID, @TempCId);
END TRY
BEGIN CATCH
END CATCH;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With