Technical Article

List all primary keys

,

Thanks to Raul Sharma for his brilliant ideas. This is a modification of one of his scripts. The script takes only the user tables. Those tables which does not have PK are not listed!

SELECT  table_name, column_name, ordinal_position 
FROM information_schema.key_column_usage 
WHERE constraint_catalog = db_name()
AND lower(constraint_name) like 'pk%'
AND table_name not like 'tbl_core_%'
AND table_name not like 'sys%' 
        AND table_name not like 'db_version_1%'
        AND table_name not like 'dtproperties' 
AND LOWER(constraint_name) like 'pk%'
ORDER BY table_name, column_name

Rate

4 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

4 (1)

You rated this post out of 5. Change rating