DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    JamesS Guest

    default constraint using another column in the same table and others


    Is it possible to set the defalt value of a column to the value of another
    column in the same table. For example I have tableA with columns B and C.
    I want the default value of C to be the value entered in B.

    Can I use dataflow constructs(if,else, case) on a check constraint? Using
    the aforementioned table, suppose that column B can be null, and I want to
    create a check constraint such that B < C, can I create a constraint such
    that it is only invoked if both B and C are not null?

    The pseudocode:
    if b is not null then
    impose check constraint(B should be less than C)
    otherwise
    do nothing

    Tnx

  2. #2
    DaveSatz Guest

    Re: default constraint using another column in the same table and others

    No - you need to write a trigger. Defaults can only be constant
    expressions, .i.e. system_user or 0
    --

    HTH,
    David Satz
    Principal Software Engineer
    Hyperion Solutions
    { SQL Server 2000 SP1/7.0 SP3/6.5 SP5a } { Cold Fusion 5/4.5.1 SP2 } { VSS }
    (Please reply to group only - emails answered rarely)
    This posting is provided "AS IS" with no warranties, and confers no rights.
    You assume all risk for your use.
    -----------------------------------------------------------------

    "JamesS" <gipanuhot@yahoo.com> wrote in message
    news:3be6cd52$1@147.208.176.211...
    >
    > Is it possible to set the defalt value of a column to the value of another
    > column in the same table. For example I have tableA with columns B and C.
    > I want the default value of C to be the value entered in B.
    >
    > Can I use dataflow constructs(if,else, case) on a check constraint? Using
    > the aforementioned table, suppose that column B can be null, and I want to
    > create a check constraint such that B < C, can I create a constraint such
    > that it is only invoked if both B and C are not null?
    >
    > The pseudocode:
    > if b is not null then
    > impose check constraint(B should be less than C)
    > otherwise
    > do nothing
    >
    > Tnx




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