How to get the unique indexes in a certain Db

  • Hi,

    I would like to know how to get the unique indexes in a certain Db.

    Thanks a lot.

    Maricar

  • Try this:

    SELECT so.name [Table], si.name [Index] 
    FROM dbo.sysobjects so
      JOIN dbo.sysindexes si
        ON so.id = si.id
    WHERE INDEXPROPERTY(so.id, si.name, 'IsUnique') = 1
      AND so.xtype = 'U'
    ORDER BY [Table], [Index]

    If you want system tables as well, drop the so.xtype = 'U' line.

    K. Brian Kelley
    @kbriankelley

  • OK, Thanks a lot. It helps me a lot. BTW, I would also like to know the columns of which is indexed.

    Thanks.

     

     

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply