Is it posible to have 2 or more column in a single constraint

  • hi all,

          Is it posible to have 2 or more column in a single constraint. if its possible in what condition it may come...

        Because, in my application i have to drop one column. so, before going to drop the column we have to drop the indexes and constraints in which this column present. so, i will drop the constraints by selecting the appropriate constraint in which the column present.. at this time i got the above doubt...

    Thanks & Regards

    G.S.K

     

  • Yes is possible to have 2 or more colums in one constraint (table constraints)

    CREATE TABLE [dbo].[TestTBL] (

     [Col1] [int] NULL ,

     [Col2] [int] NULL ,

     [Col3] [int] NULL

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[TestTBL] ADD

     CONSTRAINT [CK_TestTBL] CHECK ([col1] < [col2] and [col2] < [col3])

    GO

     


    Kindest Regards,

    Vasc

  • in column level constraint is it possible??

    and in which case we will have column level constraints

     

    Thanks & regards

    G.S.K

  • < column_definition > ::=

        { column_name data_type }

        [ [ DEFAULT constant_expression ] [ WITH VALUES ]

        | [ IDENTITY [ (seed , increment ) [ NOT FOR REPLICATION ] ] ]

            ]

        [ ROWGUIDCOL ]

        [ COLLATE < collation_name > ]

        [ < column_constraint > ] [ ...n ]

    < column_constraint > ::=

        [ CONSTRAINT constraint_name ]

        { [ NULL | NOT NULL ]

            | [ { PRIMARY KEY | UNIQUE }

                [ CLUSTERED | NONCLUSTERED ]

                [ WITH FILLFACTOR = fillfactor ]

                [ ON { filegroup | DEFAULT } ]

                ]

            | [ [ FOREIGN KEY ]

                REFERENCES ref_table [ ( ref_column ) ]

                [ ON DELETE { CASCADE | NO ACTION } ]

                [ ON UPDATE { CASCADE | NO ACTION } ]

                [ NOT FOR REPLICATION ]

                ]

            | CHECK [ NOT FOR REPLICATION ]

                ( logical_expression )

        }

    < table_constraint > ::=

        [ CONSTRAINT constraint_name ]

        { [ { PRIMARY KEY | UNIQUE }

            [ CLUSTERED | NONCLUSTERED ]

            { ( column [ ,...n ] ) }

            [ WITH FILLFACTOR = fillfactor ]

            [ ON {filegroup | DEFAULT } ]

            ]

            |    FOREIGN KEY

                [ ( column [ ,...n ] ) ]

                REFERENCES ref_table [ ( ref_column [ ,...n ] ) ]

                [ ON DELETE { CASCADE | NO ACTION } ]

                [ ON UPDATE { CASCADE | NO ACTION } ]

                [ NOT FOR REPLICATION ]

            | DEFAULT constant_expression

                [ FOR column ] [ WITH VALUES ]

            |    CHECK [ NOT FOR REPLICATION ]

                ( search_conditions )

        }

    columns contraints refers to 1 column in the table


    Kindest Regards,

    Vasc

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

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