Select distinct Tbl.name, col.name From
sys.tables Tbl Join sys.columns col on col.[object_id] = Tbl .[object_id]Join sys.index_columns idx_cols on idx_cols.[column_id] = col.[column_id] and idx_cols.[object_id] = col.[object_id]
Join sys.indexes idx on idx_cols.[index_id] = idx.[index_id] and idx.[object_id] = col.[object_id]where col.name = 'INT_EMP_ID'and idx.is_unique = 1
This query finds table names,column names where columns are having primary key or unique key or its unique index is set to 1.
By default this query works on all tables in database thus time efficient.
User can alter this query for selectiong scope to a single table or group of tables or complete database depending upon his necessity.
sys.tables Tbl Join sys.columns col on col.[object_id] = Tbl .[object_id]Join sys.index_columns idx_cols on idx_cols.[column_id] = col.[column_id] and idx_cols.[object_id] = col.[object_id]
Join sys.indexes idx on idx_cols.[index_id] = idx.[index_id] and idx.[object_id] = col.[object_id]where col.name = 'INT_EMP_ID'and idx.is_unique = 1
This query finds table names,column names where columns are having primary key or unique key or its unique index is set to 1.
By default this query works on all tables in database thus time efficient.
User can alter this query for selectiong scope to a single table or group of tables or complete database depending upon his necessity.
3:03 AM
Mohit Vashisht

