Check Constraint


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Check Constraint

  1. #1
    TTT Guest

    Check Constraint


    I would like to place a check constraint on a column in 1 table against another
    column in a separate table.

    For example:

    if T1.Col1 = 1
    then T2.Col1 = 1 or 2

    I have done check constraints on single tables but never with 2 or more.

    Thanks

  2. #2
    Rune Bivrin Guest

    Re: Check Constraint

    "TTT" <ttt@ttt.net> wrote in news:3e6c016b$1@tnews.web.devx.com:

    >
    > I would like to place a check constraint on a column in 1 table
    > against another column in a separate table.
    >
    > For example:
    >
    > if T1.Col1 = 1
    > then T2.Col1 = 1 or 2
    >
    > I have done check constraints on single tables but never with 2 or
    > more.
    >
    > Thanks
    >


    The general rule is that constraints can only work with constants and other
    columns in the same table. It's possible to work around this in SQL2K by
    using a user defined function as the test for the column.

    --
    Rune Bivrin
    - OOP since 1989
    - SQL Server since 1990
    - VB since 1991

  3. #3
    TTT Guest

    Re: Check Constraint


    Rune Bivrin <rune@bivrin.com> wrote:
    >"TTT" <ttt@ttt.net> wrote in news:3e6c016b$1@tnews.web.devx.com:
    >
    >>
    >> I would like to place a check constraint on a column in 1 table
    >> against another column in a separate table.
    >>
    >> For example:
    >>
    >> if T1.Col1 = 1
    >> then T2.Col1 = 1 or 2
    >>
    >> I have done check constraints on single tables but never with 2 or
    >> more.
    >>
    >> Thanks
    >>

    >
    >The general rule is that constraints can only work with constants and other


    >columns in the same table. It's possible to work around this in SQL2K by


    >using a user defined function as the test for the column.
    >
    >--
    >Rune Bivrin
    > - OOP since 1989
    > - SQL Server since 1990
    > - VB since 1991


    I accomplished what I wanted to with triggers but did not accomplish my main
    goal. I was attempting to show the benefits of xml schemas with the validation
    of objects but could not get the cross object constraint to work. Found
    another way.
    Thanks


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center