1. Select the database and open a new query window.
2. Pass the table name to @table_name variable.
3. Run the script.
Kiran Kumar,
2009-01-02 (first published: 2008-12-10)
1. Select the database and open a new query window.
2. Pass the table name to @table_name variable.
3. Run the script.
declare @table_name nvarchar(50) set @table_name = 'Sample' select c.name as [Column_Name], kc.name as [Constraint_Name], object_name(c.object_id) as [Table_Name] from sys.columns c join sys.key_constraints kc on (c.column_id = kc.unique_index_id and c.object_id = kc.parent_object_id) where kc.type='UQ' -- or kc.type = 'PK' and c.object_id = object_id(@table_name)
As the title says, the clustered index doesn't have to the primary key and vice versa.
2016-05-24
260 reads
This procedure let you list [optional] by table:
-Foreign keys
-Primary key
-Indexes
2015-03-27 (first published: 2014-02-06)
3,955 reads
2010-03-10
4,301 reads