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.
It is strange that one can ask simple questions about extended events or Hekaton at professional events and conferences without feeling embarrassed, yet nobody likes to ask vital questions about SQL Server primary keys and foreign keys. Fear not, here are 13 questions you were too shy to ask, answered.
2014-10-14
9,933 reads
I inherited a database that was getting large and not performing well. After adding primary keys life got better.
Every database developer uses keys, but without always understanding all the ramifications. They come with few hard and fast rules, but if you get them right from the start with a database design, the whole process of database development is simpler, and the result is likely to perform better. We asked Phil for advice, little knowing that the explanation might take a while.
2013-12-19
5,005 reads
Output table of gaps in a primary key across multiple databases on same, remote and/or linked servers.