Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting PKs of Tables
Message
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00755682
Message ID:
00755699
Views:
17
This message has been marked as the solution to the initial question of the thread.
Mark,

Try
SELECT * FROM   INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
	JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu 
		ON tc.CONSTRAINT_name = ccu.CONSTRAINT_name 
	WHERE CONSTRAINT_type = 'PRIMARY KEY' 
>In Oracle, the following SQL will return a cursor of tables and what columns are indexed as the Primary Key for each table. What SQL will return the same for SQL Server? TIA!
>select
>  B.Constraint_Type,
>  A.Index_Name,
>  A.Table_Name,
>  A.Column_Name
> from
>  User_Constraints B, User_Ind_Columns A
> where A.Index_Name = B.Constraint_Name
>   and B.ConstraintType = 'P'
> order by A.Table_Name
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform