Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

query to get all primary keys and foreign key

SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects 
WHERE type_desc IN ('FOREIGN_KEY_CONSTRAINT','PRIMARY_KEY_CONSTRAINT')
GO
 
PREVIOUS NEXT
Tagged: #query #primary #keys #foreign #key
ADD COMMENT
Topic
Name
2+7 =