June 28, 2004 at 3:11 pm
I have a need to use the system tables to create a sql script for the indexes defined for a table. I cannot figure out how to tell whether the index id defined as unique or not from the system tables.
TIA for any help here.
June 28, 2004 at 4:04 pm
I'm not sure about sysindexes, possibly the status column, but you'd have to decipher it.
You could load the output from sp_helpindex into a temporary table, and check the description column to be LIKE '%unique%' .
Steve
June 28, 2004 at 5:21 pm
That is actually found in the sysobjects table like so.
select object_name(o.parent_obj) [Parent Name], o.[name] [Index_Name], o.xtype Type, o.* from sysobjects o
where o.xtype in ('PK','UQ')
June 29, 2004 at 12:18 am
One might consider having a look at
INDEXPROPERTY(...,'IsUnique')
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
June 29, 2004 at 12:19 am
You can find the info you need in the master.dbo.spt_values table. Following script lists all indexes that will be uniqe ( unique, primary key or unique key ). I got this info from the sp_helpindex procedure ...
select table_name = object_name(I.id),I.indid, index_name = I.name, I.status
from sysindexes I
where I.indid > 0 and I.indid < 255 and (I.status & 64)=0
and exists ( select 1 from master.dbo.spt_values S where S.type = 'I' and S.name in ( 'unique','primary key','unique key' ) and S.number & I.status <> 0 )
order by id,indid
June 29, 2004 at 8:33 am
Thanks to all for the ideas. Bert De Haes' answer worked for me.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy