check constraint???????

  • Hello friends

    I have two tables like Master_E and Child_E

    CREATE TABLE [Master_E] (

     [ID] [int] NOT NULL ,

     [Name] [varchar] (4) ,

     [T_Delete] [varchar] (1) here that check constraint i want to put,

     CONSTRAINT [PK_Test_TM] PRIMARY KEY  CLUSTERED

     (

      [ID]

    &nbsp  ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    CREATE TABLE [Child_E] (

     [ID] [int] NOT NULL ,

     [Name] [varchar] (4) ,

     [T_Delete] [varchar] (1) 

    &nbsp GO

    insert into Master_E values (1,'SA', null)

    insert into Master_E values (2,'GG', null)

    insert into Master_E values (3,'GS', null)

    insert into Child_E values (1,'SA', null)

    insert into Child_E values (2,'GG', null)

     

    Now I want to set flag either yes or no for column T_Delete of Master table.

    In master table it is Y if no records found in child table for ID and In master table it is N if records found in child table for ID...but all these things i want from check constraint only..How should i put that check constraint on column T_Delete

    for maste table...pls any idea...most welcome

     

     

     


    Regards,

    Papillon

  • You can't do this with a constraint... you'll need to use a trigger or, maybe, you can also try a "calculated column".

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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