When trying to optimize SQL scripts, I was recommended to add indexes.
What is the easiest way to indicate in which database the pointer should be?
IF EXISTS (SELECT * FROM sysindexes WHERE NAME = 'idx_TableA') DROP INDEX TableA.idx_TableA IF EXISTS (SELECT * FROM sysindexes WHERE NAME = 'idx_TableB') DROP INDEX TableB.idx_TableB
In the above code, TableA is in DB-A, and TableB is in DB-B.
When changing DROP INDEX TableA.idx_TableA to DROP INDEX DB-A.dbo.TableA.idx_TableA
The following error appears:
Msg 166, Level 15, State 1, Line 2 'DROP INDEX' does not allow specifying the database name as a prefix to the object name.
Any thoughts are appreciated.
source share