Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to pull out the PK field for the table
Message
De
16/09/2008 10:12:20
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01347071
Message ID:
01347907
Vues:
9
You are welcome!
And thank you from me for sharing the knowledge!
Zahid

>>>>Hi
>>>>
>>>>EXEC sp_pkeys @table_name = tableName
>>>>
>>>>
>>>
>>>Is it the only way? I want to create a query, how would I use this sp in a query? I'm not on a computer with SQL Server, can't test at the moment.
>>
>>As far as i know
>>Insert data returned by sp_pkeys in #temp and use in you query.
>
>Here is the code that worked for me
>
>select tc1.PK_Field, col.Table_Name, col.Column_Name, col.Data_Type, col.Character_Maximum_Length 
>from INFORMATION_SCHEMA.COLUMNS col 
>INNER JOIN INFORMATION_SCHEMA.TABLES tab on col.Table_Name = tab.Table_Name 
>LEFT JOIN (SELECT ccu.Column_Name as PK_Field, tc.Table_Name from 
>INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc 
>	INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu
>		ON tc.CONSTRAINT_name = ccu.CONSTRAINT_name 
>WHERE CONSTRAINT_type = 'PRIMARY KEY') tc1 ON col.Table_Name = tc1.Table_Name 
>WHERE tab.Table_Type = 'BASE TABLE' AND col.Character_Maximum_Length >=100 order by 2,3
>
>
>Thanks again for your help.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform