Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return the colid of primary key for table
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00663859
Message ID:
00663919
Vues:
26
>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'
Thanks Sergey. I'm going to spend some time getting familiar with the Information Schema views and the info they provide.
Al Williams

Anola MB, CANADA
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform