Cari Blog Ini

28 Juni 2012

How To Check Primary Key of Table

1. Sample of Design Table






2. Display related columns
----------------------------------------------------------
-----code:start
----------------------------------------------------------
SELECT
        col.name
        ,col.colid
        ,col.isnullable
        ,typ.name
FROM syscolumns col
JOIN systypes typ on col.xtype=typ.xtype
WHERE id = OBJECT_ID('mskaryawan')
----------------------------------------------------------
-----code:end
----------------------------------------------------------





3. Run this query, for check only Primary Key Columns
----------------------------------------------------------
-----code:start
----------------------------------------------------------
SELECT
        col.name
        ,col.colid
        ,col.isnullable
        ,typ.name
FROM syscolumns col
JOIN systypes typ on col.xtype=typ.xtype
WHERE id = OBJECT_ID('mskaryawan')
AND IsNullable=0
----------------------------------------------------------
-----code:end
----------------------------------------------------------