We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

SQL DMO - deleting indexes - cant delete DRI Generated

valhallatech
valhallatech asked
on
Medium Priority
621 Views
Last Modified: 2008-01-09
Hi sql heads - I'm itterating through tables using sqldmo (in vba) and then itterating through indexes on that table and issueing a remove. I have an indexes it refuses to delete, instead giving an error (I didnt write number  down, but can get on request) saying that it can delete a "DRI generated" unique contraint or primary key. An interesting thing to note is that this index is of type 18450, where as most of the other indexes are of a type that can be found on the SQLDMO_INDEX_TYPE index constants page in the books online.

anyhow, is there any way I can delete these with sqldmo?
thanks
Comment
Watch Question

Top Expert 2006

Commented:
These indexes are constraint primary keys. You cannot use same satement which you are using to delete indexes in these case.
Top Expert 2006

Commented:
if you are using .Indexes property of the object use .keys property.

Author

Commented:
hmm... I thought of that, but the .keys collection was empty, so there was nothing to delete. Though I'll go and look at this again and double check.

Author

Commented:
hi imran_fast
you're right - at least partly. there is a key - so I used .keys.remove, but this still didnt stop the error (-2147201005) from occuring, and so I still cant delete that index. I also executed a .primarykey.remove, but that still doesnt allow me to delete the index wiht out getting the error:
-2147201005
"[SQL-DMO] This index was generated by a DRI 'PRIMARY KEY' or 'UNIQUE KEY' CONSTRAINT and cannot be modified or droped" when I try the .index(x).remove (having already done .key(x).remove)

where to from here?
Top Expert 2006
Commented:
Create a Key object.
Set the Type property to SQLDMOKey_Primary.
Add the Key object to the Keys collection of a Table object that exposes the attributes of the SQL Server table.
then use the remove property to delete it.


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
just to confirm - when you say 'then use the remove property to delete it.' - you mean the index, not the new key?
Top Expert 2006

Commented:
yes to remove  the primary key index

Author

Commented:
bingo - thankyou
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.