SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


List Table Foreign Keys, Primary key and indexes


List Table Foreign Keys, Primary key and indexes

Author
Message
v.collazos
v.collazos
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 76
Comments posted to this topic are about the item List Table Foreign Keys, Primary key and indexes
MariusJarzebowski
MariusJarzebowski
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 89
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
m mcdonald
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1898 Visits: 1680
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
nhfeldman
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 171
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
Robert.Sterbal
Old Hand
Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)

Group: General Forum Members
Points: 335 Visits: 2000
I always appreciate seeing the underlying queries for stored procedures

the script here offers more flexibility then the sp_help function

Thanks!
Iwas Bornready
Iwas Bornready
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13772 Visits: 885
Nice script, thanks.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search