Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
heliang
Starting Member
38 Posts |
Posted - 2015-01-21 : 13:09:25
|
I am trying to run multiple SQL statement as followingdrop index XXX on XXgodrop index XXX on XXgodrop index XXX on XXgobut 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! |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2015-01-21 : 13:12:29
|
GO isn't T-SQL syntax. It is a batch separator for things like sqlcmd and a query window in SSMS. You could use multiple execute SQL tasks. Or you could wrap the code in a stored procedure. Or you could try passing the whole thing into sp_executesql.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
viggneshwar
Yak Posting Veteran
86 Posts |
Posted - 2015-01-28 : 09:40:49
|
use the below codeIF EXISTS(SELECT * FROM SYS.INDEXES WHERE OBJECT_NAME(OBJECT_ID)= 'TableName' AND NAME='IndexName' )DROP INDEX xxx ON xx RegardsViggneshwar A |
|
|
|
|
|