To find column with constraint

  • Hi Experts,

    I need to find a column from a partciular database and its related constraint.I have the column name with me.The column is having not null constraint How can i achieve the same?

  • View INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE may meet your needs.

    Returns one row for each column in the current database that has a constraint defined on the column. This information schema view returns information about the objects to which the current user has permissions.

    SQL = Scarcely Qualifies as a Language

  • The system view you need is sys.columns, look at the is_nullable column on that view.

    The following example shows all objects (tables/views...) in the AdventureWorks sample database that contain a column called EmployeeID, constrained to be not nullable.

    USE AdventureWorks;

    SELECT OBJECT_NAME(C.[object_id])

    FROM AdventureWorks.sys.columns C

    WHERE C.name = N'EmployeeID'

    AND C.is_nullable = 'false';

  • if you know table name then try sp_help tablename.

    then you will get all the details you want for that perticualr table....

    ----------
    Ashish

  • ashish.kuriyal (3/19/2010)


    if you know table name then try sp_help tablename.

    then you will get all the details you want for that perticualr table....

    A handy shortcut is to highlight the table name and hit Alt-F1 in SSMS.

    My guess is that the OP was looking for a programmatic solution, however.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply