Created
July 26, 2013 16:33
-
-
Save kmoormann/6090291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--USE <REPLACE WITH DATABASE NAME> | |
CREATE TABLE #tablesOfInterest (TableName VARCHAR(2000)) | |
INSERT INTO #tablesOfInterest | |
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES | |
WHERE TABLE_NAME | |
IN ('table1' | |
,'table2' | |
) | |
SELECT tableName, keyColumn.constraint_name as PrimaryKey | |
FROM #tablesOfInterest toi | |
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE keyColumn | |
ON toi.tableName = keyColumn.TABLE_NAME | |
AND OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1 | |
WHERE keyColumn.Table_Name IS NULL | |
DROP TABLE #tablesOfInterest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment