Retrieving Primary Key columns from system tables
Hello,
I'm trying to retrieve table name, field name, datatype, length, null/not null, primary key from system tables. I'm able to pull successfull all of them except primary key columns. Can anyone please help me. Here is my sql query.
select a.name as TableName,b.name as FieldName,c.name as Datatype,b.length as Length,
AllowNulls = (CASE
WHEN b.isnullable=0 THEN 'NOT NULL'
WHEN b.isnullable=1 THEN 'NULL'
END)
from sysobjects a,syscolumns b,systypes c
where a.type='U'
and a.id = b.id and c.xtype=b.xtype
order by a.name,b.colorder
I want to add the primary key column, saying if the field is a primary key it should display as yes otherwise no.
I hope someone can help me. I have been trying this from a long time. I need this immediately.
Thanks for your help in advance.
|