lcaraballo
5/10/2016 - 1:30 PM

Mostrar todas las claves primarias de la base actual seleccionada SQL SERVER http://stackoverflow.com/questions/95967/how-do-you-list-the-pr

Mostrar todas las claves primarias de la base actual seleccionada SQL SERVER http://stackoverflow.com/questions/95967/how-do-you-list-the-primary-key-of-a-sql-server-table

SELECT 
     COLUMN_NAME,
     Tab.TABLE_NAME 
FROM 
     INFORMATION_SCHEMA.TABLE_CONSTRAINTS Tab, 
     INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE Col
WHERE 
     Col.Constraint_Name = Tab.Constraint_Name AND 
     Col.Table_Name = Tab.Table_Name AND
     Constraint_Type = 'PRIMARY KEY' 
ORDER BY 
     COLUMN_NAME