retreiving metadata information of s database
-
I need to retrieve the primary key column name for the given table. The data given is: Table name The data to be extracted is: primary key column name Can anyone help me out in this
You don't specify which database product you are using so I shall assume it is SQL Server 2000.
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
ON tc.CONSTRAINT_NAME = ccu.CONSTRAINT_NAME
WHERE CONSTRAINT_TYPE='PRIMARY KEY'
AND tc.TABLE_NAME = 'MyTable'This assumes also that there is only one schema (dbo) or that there are no tables with the same name in different schemas. Does this help?
Do you want to know more? WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums
-
You don't specify which database product you are using so I shall assume it is SQL Server 2000.
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
ON tc.CONSTRAINT_NAME = ccu.CONSTRAINT_NAME
WHERE CONSTRAINT_TYPE='PRIMARY KEY'
AND tc.TABLE_NAME = 'MyTable'This assumes also that there is only one schema (dbo) or that there are no tables with the same name in different schemas. Does this help?
Do you want to know more? WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums