so i make a database with mysql, with my database design i design 3 table (customer, product, order) and I need one of the table to have a boolean variable column. in that column I need to use constraint when the value is 0 so u cant add the product to the order table.
drop database trial;
create database trial;
use trial;
create table customer_details(
customer_id int not null,
customer_name varchar(100) not null,
customer_contact varchar(100) not null,
customer_address varchar(100) not null,
primary key(customer_id)
);
create table product_details(
product_id int not null,
product_name varchar(100) not null,
product_finishing varchar(100) not null,
product_price varchar(100) not null,
product_stock int check(product_stock >=0) not null,
product_condition_1ready_0mentah boolean not null check(1 >= product_condition_1ready_0mentah AND product_condition_1ready_0mentah >=0),
primary key(product_id,product_stock)
);
create table order_details(
order_id varchar(50) not null,
order_quantity int not null check(order_quantity > 0),
customer_id int not null,
product_id int not null,
order_date date not null,
order_desc varchar(255),
primary key(order_id),
FOREIGN KEY (customer_id) REFERENCES customer_details(customer_id),
FOREIGN KEY (product_id) REFERENCES product_details(product_id)
);
insert into product_details(product_id, product_name, product_finishing, product_price, product_stock, product_condition_1ready_0mentah)
values
(1, "meja", "ash", "Rp 10000", 10, true),
(2, "kursi", "redwood", "Rp 20000", 20, true),
(3, "panel", "maple", "Rp 300000", 20, false);
insert into customer_details(customer_id, customer_name, customer_contact, customer_address)
values
(1, "Test Meubel", "08987654321", "Solo");
insert into order_details(order_id, order_quantity, customer_id, product_id, order_date, order_desc)
values
("12345", 10, 1, 1, "2020-12-20", "Bla Bla Bla"),
("54321", 5, 1, 2, curdate(), "Notes bisa dimasukin sini");
so for the product_condition I need to have constraint if its false I cant add order for that specific product what I need to do