Testing to see if table constraints were created

  • Hi all!!

    I am writing simple test scripts to see if columns and constraints were created. I know that I can find out info using the sp_helpconstraint stored procedure, but I need to check specifically for each. Here is an example of my test for column creation and I am wondering is there a similar way to do it for the constraints?? Thank you in advance, as always!!

    IF EXISTS (SELECT * FROM dbo.syscolumnssc,

    dbo.sysobjectsso

    WHERE so.id= sc.id

    and so.name = 'ExistingTable'

    and sc.name = NewColumn'

    and so.xtype = 'U' )

    BEGIN

    SELECT PassFail = 'PASS: NewColumn has been added to ExistingTable table',

    'Miss Dev' AS Developer,

    getdate() as [Last Modified]

    END

    ELSE

    BEGIN

    SELECT 'Fail: NewColumn has NOT been added to ExistingTable table',

    'Miss Dev' AS Developer,

    getdate() as [Last Modified]

    END


    Thank you!!,

    Angelindiego

  • Try using INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE or INFORMATION_SCHEMA.CHECK_CONSTRAINTS. There are a few other similar views that will be helpful. See BOL.

  • thankyou, I am headed there now!!


    Thank you!!,

    Angelindiego

Viewing 3 posts - 1 through 2 (of 2 total)

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