Find Invalid Objects cannot detect nonexistent tables in trigger
a.higgins
Posts: 90 Bronze 2
in SQL Prompt
When I look in a database for invalid objects, it cannot detect triggers that reference tables that do not exist.
Since I use triggers to maintain referential integrity, this can bite me if I ever deploy something to Production that contains a reference to a new object that still is undergoing UAT (and yes, we got a middle-of-the-night phone call after our last deploy to fix this).
Part of our release process is to run the Find Invalid Objects check in the database after all deployments, so it would be nice if that could be expanded to detect a problem like the following:
DROP TABLE IF EXISTS dbo.DummyTable
GO
GO
CREATE TABLE dbo.DummyTable (SomeColumn INT NOT NULL)
GO
CREATE TRIGGER TR_ThisWillNotWork
ON dbo.DummyTable
AFTER DELETE
AS
BEGIN
DELETE FROM InvalidObjectThatDoesNotExist WHERE 1 = 1
END
GO
After creating the table and trigger above on an empty database, Find Invalid Objects returns no results. GO
CREATE TRIGGER TR_ThisWillNotWork
ON dbo.DummyTable
AFTER DELETE
AS
BEGIN
DELETE FROM InvalidObjectThatDoesNotExist WHERE 1 = 1
END
GO
Tagged:
Answers
What version of SQL Prompt are you using? This should have been fixed in version 9.5.3.9640 (see the release notes here).
Kind regards,
Alex
Have you visited our Help Center?
Version 9.5.3 (with build number 9640) is near the bottom from 14 May last year. Having said that it doesn't seem to be working for me either.
I'm going to escalate this to the development team and I will update here when I have further information.
Kind regards,
Alex
Have you visited our Help Center?
My apologies, but after discussing with the team and re-reading what was in the release notes, it seems I was wrong.
The fix was to find triggers that are on non-existent tables rather than triggers that include non-existent tables in their actions. The latter isn't picked up because it doesn't throw an error during compilation of the object (where the former does) and that is the mechanism that is used by SQL Prompt when finding invalid objects.
So I'm afraid this isn't going to find what you are wanting it to find.
However there is this bit of code does find the trigger in the latter case (that references an invalid object in it's action):
Hopefully that will help!
Kind regards,
Alex
Have you visited our Help Center?
Glad it is useful!
I hope that it will be added, though as of now I've let the team know but it's not currently something they're working on.
Sorry I can't be more precise!
Kind regards,
Alex
Have you visited our Help Center?