Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return the colid of primary key for table
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00663859
Message ID:
00663890
Views:
29
My previous solution returns object id for the primary index not for the columns in it. Sory about that confusion. I think, this select provides what you're looking for.
SELECT c.column_name, ordinal_position
 FROM   INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
	JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu 
		ON tc.CONSTRAINT_name = ccu.CONSTRAINT_name 
			AND tc.table_name = ccu.table_name
	JOIN INFORMATION_SCHEMA.COLUMNS c 
		ON ccu.Column_name = c.Column_name
			AND ccu.table_name = c.table_name
	WHERE CONSTRAINT_type = 'PRIMARY KEY' 
		And tc.table_name = 'titles'
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform