Question

My table structure is as follows:

create table Sale(
    id int primary key,
    product_ID int foreign key references ItemCategory.Item_Details(item_id),
    product_name varchar(10),
    unit_price int,
    quantity int,
    discount int,
    total_price int,
    profit int
)  

Now I have to implement the following constraints in the sale table: The discount offered on a product should not be greater than 20% of the unit price of the product.

Was it helpful?

Solution

ALTER TABLE Sale
  ADD CONSTRAINT ValidDiscount
  CHECK(discount <= unit_price *0.2);

This is ANSI 92, but IIRC not all RDBMS support it... MySQL doesn't.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top