Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Check Constraints

Author  Topic 

bimpex
Starting Member

3 Posts

Posted - 2009-02-07 : 05:30:43
hai all,

wishes,
i am very new to sql server
i am creating a table in that i want to make Check Constraints
for column3 and column4 should be null are notnull
(eigher one only should not have value, both have no value or value)

thanks in advance
rcs
---------
-------
AC_HD_NAME_DR1 VARCHAR2(30)not null
JR_AMT_DR1 MONEY(20,2) not null
AC_HD_NAME_DR2 VARCHAR2(30)
JR_AMT_DR2 MONEY(20,2)
-----

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-07 : 08:48:42
do you mean this?

ALTER TABLE tablename ADD CONSTRAINT CHK_Col3_Col4 CHECK (Column3 IS NOT NULL OR Column4 IS NOT NULL)
Go to Top of Page

bimpex
Starting Member

3 Posts

Posted - 2009-02-07 : 09:33:10
i need like this:

1.both column can be null
2.both column can be not null
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-07 : 09:40:41
[code]ALTER TABLE tablename ADD CONSTRAINT CHK_Col3_Col4 CHECK ((Column3 IS NOT NULL AND Column4 IS NOT NULL) OR (Column3 IS NULL AND Column4 IS NULL))[/code]
Go to Top of Page

bimpex
Starting Member

3 Posts

Posted - 2009-02-07 : 10:00:43
hai,
visakh16

your ans solved my prob

thank you

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-07 : 10:03:36
welcome
Go to Top of Page
   

- Advertisement -