0 Replies - 2403 Views - Last Post: 06 December 2011 - 01:34 PM

#1 Dev1462  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 145
  • Joined: 20-May 10

Problems with check constraints and conditions

Posted 06 December 2011 - 01:34 PM

After about an hour of trying on my own I've come to seek help, I'm trying to add a check constraint to basically say that if the value of "payment_total = 0" then allow "payment_date" column to be null, while also saying that if "payment_total > 0" to allow payment_date to be not null. Here is the full question for references:

Quote

1. Write an ALTER TABLE statement that adds two new check constraints to the Invoices tables of the AP Schema. The first should allow (1) payment_date to be null only if the payment_total is zero and (2) payment_date to be not null only if payment_total is greater than zero. The second constraint should prevent the sum of payment_total and credit_total from being greater than invoice_total.


ALTER TABLE invoices
ADD CONSTRAINT payment_date_ck 
check ((payment_date is null) and (payment_total = 0));



Is This A Good Question/Topic? 0
  • +

Page 1 of 1