DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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


Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links