List all the Primary and Foreign keys in SQL Server database

To list all the Primary keys in a SQL Server database run:

USE Database_name
SELECT * FROM information_schema.table_constraints
WHERE constraint_type = 'Primary Key'

To list the Primary key in a table in a SQL Server database run:

USE Database_name
SELECT * FROM information_schema.table_constraints
WHERE constraint_type = 'Primary Key' and Table_Name = 'Table_name'

To list all the Foreign keys in a SQL Server database run:

USE Database_name
SELECT * FROM information_schema.table_constraints
WHERE constraint_type = 'Foreign Key'

To list all the Foreign keys in a table in a SQL Server database run:

USE Database_name
SELECT * FROM information_schema.table_constraints
WHERE constraint_type = 'Foreign Key' and Table_Name = 'Table_name'