List of all the primary key and foreign key table and column names
|
SELECT distinct
SCHEMA_NAME(SOF.SCHEMA_ID) as PK_SCHEMA ,object_name(rkeyid) as PK_TABLE , C.name as PK_COL,SCHEMA_NAME(SOF.SCHEMA_ID) AS FK_SCHEMA ,object_name(fkeyid) as FK_TABLE,b.name as FK_COL FROM sys.sysforeignkeys A left outer join syscolumns b on a.fkeyid = b.id and a.fkey = b.colid left outer join syscolumns c on a.rkeyid = c.id and a.rkey = c.colid left outer JOIN sys.objects SOF ON SOF.OBJECT_ID = A.FKEYID |
Wednesday, September 30, 2009
List of all the primary key and foreign key table and column names
Subscribe to:
Post Comments (Atom)
Featured Post
SQL Server AWS Migration BCP
stored procedure to generate BCP scritps to migrate the SQL Server database. Developed this stored procedure on my labs to simulate t...
-
query execution in the production taking long time one of the query in the production taking almost 40 minutes instead seconds where it us...
-
SQL Server Data Masking : Download code DataMasking.sql Masking data can be done through updating the confidential information in t...
-
Pivot without Aggregating with consistent and inconsistent formats: One of the most common tasks which I came across at least once in almo...
No comments:
Post a Comment