-
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
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks