views:

53

answers:

1

Hello

I need to get schema details for the passed table name using information_schema. As part of output need ColumnName, Constraint_Name, Constraint_Type.

How can this be done

Thanks

A: 

OK SOLVED THIS AS

WITH CONSTRAINTLIST 
AS
(
SELECT KCU.TABLE_NAME, KCU.COLUMN_NAME, TC.CONSTRAINT_TYPE
FROM    INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC 
JOIN    INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU ON   KCU.CONSTRAINT_SCHEMA =     TC.CONSTRAINT_SCHEMA 
    AND KCU.CONSTRAINT_NAME = TC.CONSTRAINT_NAME 
    AND KCU.TABLE_SCHEMA = TC.TABLE_SCHEMA 
    AND KCU.TABLE_NAME = TC.TABLE_NAME 
WHERE        TC.CONSTRAINT_TYPE IN ( 'PRIMARY KEY') 
)
SELECT COL.COLUMN_NAME, CL.CONSTRAINT_TYPE FROM INFORMATION_SCHEMA.COLUMNS COL
LEFT JOIN CONSTRAINTLIST CL
ON COL.COLUMN_NAME = CL.COLUMN_NAME AND COL.TABLE_NAME = CL.TABLE_NAME
    WHERE  COL.TABLE_NAME = 'TABLE_NAME'
Nev_Rahd