?
Solved

Drop Index

Posted on 2005-04-28
11
Medium Priority
?
778 Views
Last Modified: 2007-12-19
I created a index on a table in a test database for doing some optomization.

I would now like to drop the index

When I try the following error is given.

Cannot drop the index XXXXX.XXXXX  because it does not exist in the system catalog.

I did run sp_updatestats as I thought updating the statistics would add it to the system catalog.

However I still get the same error when trying to drop the index after updating statistics.

Thanks
0
Comment
Question by:kpiller
  • 5
  • 4
  • 2
11 Comments
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13889928
What was your command when you dropped the index.  Is it something like this?

DROP INDEX <owner>.<index name>
0
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13889938
Oops, it should have been like this:

DROP INDEX <table name>.<index name>
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 13890306
If the index has been created for a primary key or unique constraint, you need to drop the constraint instead of the index; SQL will then automatically delete the related index.

ALTER TABLE yourTable
DROP CONSTRAINT constraintName
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 2

Author Comment

by:kpiller
ID: 13911475
Thanks, that did work for me.

I'm obviously a newbie with this.

So I have dropped the constraint and index but now want the constraint back. How would I go about this.

Basically I am testing some optomizing on a test database. In the event that something goes wrong when I make changes on the live database I would like to understand how to reverse my changes.

I added a index, then wanted to remove it, had to remove constraint but need to add contraint back to leave it how it was before I created the index.
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 13912582
Script out the constraint before you remove it.  You can do that from Enterprise Manager.  Then, just run the script to re-create it.
0
 
LVL 2

Author Comment

by:kpiller
ID: 13931615
I see how to script out items but I'm not sure exactly what selection will do the constraint. when I just do everything I don't see anything related to the field that the contraint was on.
Thanks
0
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13968730
>> I see how to script out items but I'm not sure exactly what selection will do the constraint <<

In the Generate SQL Scripts window, go to the Options tab and check all items under the Table Scripting Options.  This will generate the scripts for the constraints as well.  In the generated script, you should see something like ALTER TABLE ADD CONSTRAINT.
0
 
LVL 2

Author Comment

by:kpiller
ID: 13990486
I do not see ADD CONSTRAINT

This is what I get besides when it just buildes the colomns

ALTER TABLE [dbo].[TABlE] WITH NOCHECK ADD
       PRIMARY KEY  CLUSTERED
      (
            [COLUMN]
      ) WITH  FILLFACTOR = 90  ON [PRIMARY]
GO

 CREATE  INDEX [COLUMN2] ON [dbo].[TABLE]([COLUMN2]) WITH  FILLFACTOR = 90 ON [PRIMARY]
GO

 CREATE  INDEX [COLUMN3] ON [dbo].[TABLE]([COUMUN3]) WITH  FILLFACTOR = 90 ON [PRIMARY]
GO
0
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13991414
>> I do not see ADD CONSTRAINT <<

Your table doesn't seem to have constraints.  Are you sure that your table has constraints?
0
 
LVL 2

Author Comment

by:kpiller
ID: 13991888
When I do a SP_help on the table

Under Contraint_type I get

PRIMARY KEY (clustered)      PK__TABLE__3B40CD36      (n/a)      (n/a)      COLUMN
0
 
LVL 28

Accepted Solution

by:
rafrancisco earned 750 total points
ID: 13991980
This corresponds to the Primary Key, which is this part of the script:

ALTER TABLE [dbo].[TABlE] WITH NOCHECK ADD
      PRIMARY KEY  CLUSTERED
     (
          [COLUMN]
     ) WITH  FILLFACTOR = 90  ON [PRIMARY]
GO
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question