List Table Foreign Keys, Primary key and indexes

  • v.collazos

    SSC Enthusiast

    Points: 121

    Comments posted to this topic are about the item List Table Foreign Keys, Primary key and indexes

  • MJarz

    SSC Veteran

    Points: 243

    Results for "index"portion are not reliable - they show multiple columns. Example:

    table Reader with the following columns:

    DeviceID, DoorTypeID, ReaderTypeID, DegradedMode, KeypadPresent, AntipassbackTime, GuestSignout, EgressAreaID, GuestSignin, AutoRelock, HasAssociatedOtisDEC, OEInterfaceID, OtisDECHostname, OEOperationModeID, ReaderModel, FirmwareVersion, EvaluationNumber

    and two indexes:

    XIF4Reader - [EgressAreaID] ASC

    PK__Reader__7FCE2F09 - DeviceID (from PK)

    is listed as:

    IDX.index_id IDX.name IDX.type_desc IDX.is_primary_key IDX.index_column_id IDX.column_id IDX.column_name IDX.key_ordinal

    1 PK__Reader__7FCE2F09 CLUSTERED 1 1 1 DeviceID 1

    1 PK__Reader__7FCE2F09 CLUSTERED 1 1 8 EgressAreaID 1

    2 XIF4Reader NONCLUSTERED 0 1 8 EgressAreaID 1

    2 XIF4Reader NONCLUSTERED 0 1 1 DeviceID 1

  • m mcdonald

    Hall of Fame

    Points: 3180

    For the index query try

    INNER JOIN sys.index_columns b

    ON a.[object_id] = b.[object_id] and a.index_id = b.index_id

  • nhfeldman

    Grasshopper

    Points: 22

    Or, you could just run sp_help <tablename> and get all this information without any additional coding.

    Note that you cannot qualify your table name with a schema name. "sp_help dbo.MyTable" will not work, but "sp_help MyTable" will work.

    Also, sp_help will only look for an object in the current database.

  • Robert.Sterbal

    SSCrazy

    Points: 2855

    I always appreciate seeing the underlying queries for stored procedures

    the script here offers more flexibility then the sp_help function

    Thanks!

  • akljfhnlaflkj

    SSC Guru

    Points: 76202

    Nice script, thanks.

Viewing 6 posts - 1 through 6 (of 6 total)

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