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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 cant drop an index strange..

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 name
select * 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_Metrics

It gives me following error.
Msg 102, Level 15, State 1, Line 2
Incorrect 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 name
select * 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_Metrics

It gives me following error.
Msg 102, Level 15, State 1, Line 2
Incorrect 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]
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-01 : 15:08:01
Your syntax is incorrect.

DROP INDEX TableName.IndexName

If it doesn't like the dash, then put square brackets around IndexName.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

cottage125
Starting Member

32 Posts

Posted - 2008-08-01 : 15:43:45
Thanks.. very silly mistakes sometimes..
Go to Top of Page

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.
Go to Top of Page

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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog




I see now... post time difference < minute :)... sorry!
Go to Top of Page

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
Go to Top of Page

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!
Go to Top of Page
   

- Advertisement -