Subject Re: [firebird-support] adding check constraint
Author Martijn Tonies
Hi,

> 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?

Something along the lines of:

( PAYMENT_TYPE = 'CHK' and bank is not null and
branch is not null and check_no is not null and check_date is nt null )
OR
( PAYMENT_TYPE <> 'CHK')

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com