Subject Re: adding check constraint
Author kfkong
--- In firebird-support@yahoogroups.com, James <james_027@t...>
wrote:
> Good day.
>
> Iam not very familiar with using check constraint. Can somebody
here
> help me?
>
> I have a table named payment.
>
> CREATE TABLE PAYMENT (
> ID D_ID NOT NULL,
> CUSTOMER D_ID,
> PAY_DATE D_TRANSACTION_DATE,
> PAYMENT_TYPE CHAR(3) NOT NULL,
> BANK D_ID,
> BRANCH VARCHAR(15),
> CHECK_NO VARCHAR(15),
> CHECK_DATE D_TRANSACTION_DATE,
> AMOUNT D_MONEY,
> STATUS D_STATUS,
> CREATE_BY D_CREATE_BY,
> CREATE_ON D_CREATE_ON,
> EDIT_BY D_EDIT_BY,
> EDIT_ON D_EDIT_ON
> );
>
> How do I write a check constraint that will check that if
payment_type
> is equal to 'CHK' then bank, branch, check_no, check_date should
not be
> null?
>
> Thanks.
>
>
> regards,
> james


James,
Try the following statement after the last column and type:
CHECK( PAYMENT_TYPE = 'CHK' and bank is not NULL and
branch is not NULL and check_no is not NULL and check_date is not
NULL )