January 21, 2015 at 11:07 am
I am trying to run multiple SQL statement as following
drop index XXX on XX
go
drop index XXX on XX
go
drop index XXX on XX
go
but it does not recognize "go" and will not go to the second statement if the first index does not exist. What am I missing?
Thanks!
January 21, 2015 at 11:10 am
remove the GO statements.
GO statments are not a SQL command, but instead something that SQL Server Management Studio uses to split batches.
also, i'd recommend bullet proofing your code like this using EXISTs:
IF EXISTS(SELECT * FROM sys.indexes
WHERE name = 'IX_One'
AND OBJECT_NAME(OBJECT_ID) = 'PatientInsurance')
DROP INDEX IX_One ON PatientInsurance
IF EXISTS(SELECT * FROM sys.indexes
WHERE name = 'IX_Two'
AND OBJECT_NAME(OBJECT_ID) = 'PatientInsurance')
DROP INDEX IX_Two ON PatientInsurance
Lowell
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply