November 13, 2008 at 9:05 am
Why I'm getting this error It occurs when I try to add the name or type_desc fiels I've tried casting and converting the type_desc field
select 'DROP INDEX ' + object_name(s2.object_id) + '.' + s1.name + '--' + s1.type_desc
from sys.indexes s1
join sys.objects s2 on s1.object_id = s2.object_id
where s2.type_desc = 'user_table'
and s2.name not like 'ms%'
-- and s1.type_desc = 'CLUSTERED'
-- and s1.type_desc != 'CLUSTERED'
-- and s1.is_primary_key = 1
and s1.is_primary_key = 0
and s1.name is not null
John Zacharkan
November 13, 2008 at 11:19 am
i got the same error on one of my databases when i tested your code;
adding collation to the first field fixed it for me:
select 'DROP INDEX ' + object_name(s2.object_id) + '.' + s1.name + '--' + s1.type_desc COLLATE Latin1_General_CI_AS
from sys.indexes s1
join sys.objects s2 on s1.object_id = s2.object_id
where s2.type_desc = 'user_table'
and s2.name not like 'ms%'
-- and s1.type_desc = 'CLUSTERED'
-- and s1.type_desc != 'CLUSTERED'
-- and s1.is_primary_key = 1
and s1.is_primary_key = 0
and s1.name is not null
Lowell
November 13, 2008 at 11:31 am
if your intention is to drop the index then i think you dont have to specify field name,
you need to specify like this:
DROP INDEX [tablename].[indexname]
for example
DROP INDEX authors.au_id_ind
November 13, 2008 at 1:12 pm
My intention was to just drop them but wanted to point out the cluster indexes prior to execution.
Loweel thanks for the collation part of the script I haven't had a chance to use that, guess old dogs get to learn new tricks after all.
Zach
John Zacharkan
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply