| Author |
Topic |
|
cottage125
Starting Member
32 Posts |
Posted - 2008-08-01 : 14:55:59
|
| I have very strange situation When I execute this command I can see this index in sysindexes with this nameselect * from sysindexes where name = 'PK_PPRD_Metrics-2147478316'when I try to drop this index by this command,DROP INDEX PK_PPRD_Metrics-2147478316 ON PPRD_MetricsIt gives me following error.Msg 102, Level 15, State 1, Line 2Incorrect syntax near '-'.I tried with underscore and some other various combinations. Why I cant drop it?????the name from sp_help or from sysindexes is same as like PK_PPRD_Metrics-2147478316'Any suggestions??Thanks in advance |
|
|
tfountain
Constraint Violating Yak Guru
491 Posts |
Posted - 2008-08-01 : 15:07:09
|
quote: Originally posted by cottage125 I have very strange situation When I execute this command I can see this index in sysindexes with this nameselect * from sysindexes where name = 'PK_PPRD_Metrics-2147478316'when I try to drop this index by this command,DROP INDEX PK_PPRD_Metrics-2147478316 ON PPRD_MetricsIt gives me following error.Msg 102, Level 15, State 1, Line 2Incorrect syntax near '-'.I tried with underscore and some other various combinations. Why I cant drop it?????the name from sp_help or from sysindexes is same as like PK_PPRD_Metrics-2147478316'Any suggestions??Thanks in advance
The hyphen is not a valid character. To get around this, enclose the object name in brackets:DROP INDEX [PK_PPRD_Metrics-2147478316] |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-01 : 15:08:01
|
| Your syntax is incorrect.DROP INDEX TableName.IndexNameIf it doesn't like the dash, then put square brackets around IndexName.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
cottage125
Starting Member
32 Posts |
Posted - 2008-08-01 : 15:43:45
|
| Thanks.. very silly mistakes sometimes.. |
 |
|
|
tfountain
Constraint Violating Yak Guru
491 Posts |
Posted - 2008-08-01 : 15:57:20
|
| He will still need to quote the object name due to the '-'. That is the cause of his error. Even though the syntax is incorrect, he will still get the same error even if he qualifies it with the table name properly. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-01 : 16:13:13
|
| tfountain, my post wasn't in response to yours. I was replying when I saw no replies yet. You just beat me to it.I covered the dash problem in my post.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
tfountain
Constraint Violating Yak Guru
491 Posts |
Posted - 2008-08-01 : 16:52:55
|
quote: Originally posted by tkizer tfountain, my post wasn't in response to yours. I was replying when I saw no replies yet. You just beat me to it.I covered the dash problem in my post.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
I see now... post time difference < minute :)... sorry! |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-08-01 : 16:57:46
|
| It is possible that "PK_PPRD_Metrics-2147478316" is actually a primary key constraint. If it is, you will have to use an ALTER TABLE command to drop it.CODO ERGO SUM |
 |
|
|
tfountain
Constraint Violating Yak Guru
491 Posts |
Posted - 2008-08-01 : 19:44:42
|
quote: Originally posted by Michael Valentine Jones It is possible that "PK_PPRD_Metrics-2147478316" is actually a primary key constraint. If it is, you will have to use an ALTER TABLE command to drop it.CODO ERGO SUM
Good catch! |
 |
|
|
|