Link to home
Start Free TrialLog in
Avatar of valhallatech
valhallatech

asked on

SQL DMO - deleting indexes - cant delete DRI Generated

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
Avatar of imran_fast
imran_fast

These indexes are constraint primary keys. You cannot use same satement which you are using to delete indexes in these case.
if you are using .Indexes property of the object use .keys property.
Avatar of valhallatech

ASKER

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.
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?
ASKER CERTIFIED SOLUTION
Avatar of imran_fast
imran_fast

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
just to confirm - when you say 'then use the remove property to delete it.' - you mean the index, not the new key?
yes to remove  the primary key index
bingo - thankyou