Constraints in sql server

Results 1 to 2 of 2

Thread: Constraints in sql server

  1. #1
    Join Date
    Dec 1969

    Default Constraints in sql server

    Is there anyway to set up a constraint in one table that involves evaluating data from another table??<BR><BR>this is just a hypothetical:<BR>I have a table (let&#039;s call it Family) with a recursive relationship that stores parent, child and granchild records. Fields would be like :<BR><BR>ID - (pk)<BR>ParentID - (fk to ID)<BR>Type<BR>Name<BR>Addr<BR>etc...<BR><BR>then a linked table (FAM_FRIENDS) that stores info on friends and has a FK to the Family table&#039;s ID. WHat if friends can be related to children and grandchildren but not parents. so in the FAM_Friends table I want to set a constraint on the FK column so that it can include values from Family ID field, except where Type = Parent.<BR><BR>Make sense??<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Constraints in sql server

    Can&#039;t be done declaratively in T-SQL as neither assertions nor check constraints with subselects are supported. You could write a trigger to check it though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts