0% found this document useful (0 votes)
11 views3 pages

Create Table

The document outlines the creation of several database tables including customer, invoice, service, payment, payment_method, tax, user, billing_cycle, and reminder, along with their respective fields and relationships through foreign keys. It also includes sample data insertion for each table, demonstrating how customer information, invoices, services, payments, payment methods, taxes, users, billing cycles, and reminders are structured and related. The overall schema is designed to manage a billing system effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Create Table

The document outlines the creation of several database tables including customer, invoice, service, payment, payment_method, tax, user, billing_cycle, and reminder, along with their respective fields and relationships through foreign keys. It also includes sample data insertion for each table, demonstrating how customer information, invoices, services, payments, payment methods, taxes, users, billing cycles, and reminders are structured and related. The overall schema is designed to manage a billing system effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CREATE TABLE customer (

customer_id int unique,


fname varchar(20),
lname varchar(20),
contact varchar(20),
address varchar(50),
payment_id int,
payment_method_id int,
reminder_id int,
PRIMARY KEY (customer_id),
FOREIGN KEY (payment_id) REFERENCES payment (payment_id) on update
cascade,
FOREIGN KEY (payment_method_id) REFERENCES payment_method
(payment_method_id) on update cascade,
FOREIGN KEY (reminder_id) REFERENCES reminder (reminder_id) on update
cascade);

CREATE TABLE invoice (


invoice_id int unique,
Date date,
total_amount double (9,2),
status varchar (10) Check if paid or unpaid,
customer_id int,
payment_method_id int,
reminder_id int,
PRIMARY KEY (invoice_id),
FOREIGN KEY (customer_id) REFERENCES customer (customer_id) on update
cascade,
FOREIGN KEY (payment_method_id) REFERENCES payment_method
(payment_method_id) on update cascade,
FOREIGN KEY (reminder_id) REFERENCES reminder (reminder_id) on update
cascade);

CREATE TABLE service (


service_id int unique,
price double (9, 2),
invoice_id int, FK
user _id int, FK
PRIMARY KEY (service_id),
FOREIGN KEY (invoice_id) REFERENCES invoice (invoice_id) on update cascade,
FOREIGN KEY (user _id) REFERENCES user (user _id) on update cascade);

CREATE TABLE payment (


payment_id int unique,
date date,
amount double (10,2),
payment_method_id int,
PRIMARY KEY (payment_id),
FOREIGN KEY (payment_method_id) REFERENCES payment_method
(payment_method_id) on update cascade);
CREATE TABLE payment_method (
payment_method_id int unique,
cash varchar(10),
card varchar(10),
online_payment varchar(10),
customer_id int, FK
PRIMARY KEY (payment_method_id),
FOREIGN KEY (customer_id) REFERENCES customer (customer_id) on update
cascade);

CREATE TABLE tax (


tax_id int unique,
name varchar (50),
rate double (10,2),
PRIMARY KEY (tax_id));

CREATE TABLE user (


user _id int unique,
username varchar (20),
password int,
role varchar (20),
payment_id int,
tax_id int, FK)
reminder_id int, FK
PRIMARY KEY (user _id),
FOREIGN KEY (tax_id) REFERENCES payment (tax_id) on update cascade,
FOREIGN KEY (payment_id) REFERENCES payment (payment_id) on update
cascade,
FOREIGN KEY (reminder_id) REFERENCES reminder (reminder_id) on update
cascade);

CREATE TABLE billing_cycle (


billing_cycle_id int unique,
name varchar(30),
frequency varchar (20),
user _id int, FK
customer_id int, FK
PRIMARY KEY (billing_cycle_id),
FOREIGN KEY (user _id) REFERENCES user (user _id) on update cascade,
FOREIGN KEY (customer_id) REFERENCES customer (customer_id) on update
cascade);

CREATE TABLE reminder (


reminder_id int unique,
date date,
message int,
customer_id int,
PRIMARY KEY (reminder_id),
FOREIGN KEY (customer_id) REFERENCES customer (customer_id) on update
cascade,
FOREIGN KEY (invoice_id) REFERENCES invoice (invoice_id) on update cascade,
FOREIGN KEY (payment_id) REFERENCES payment (payment_id) on update
cascade,
FOREIGN KEY (billing_cycle_id) REFERENCES billing_cycle (billing_cycle_id) on
update cascade);

INSERTING INFORMATION
INSERT INTO customer VALUES
(“101”,”Cinco”, “Jonas”,”09617803440”,”Brgy. Sapinit”,”401”,”501”,”901”),
(“102”,”Bulos”, “Arianne”,”09163087044”,”Brgy. San Juan”,”402”,”502”,”902”),
(“103”,”Codera”, “Jambie”,”09814197155”,” Brgy. San Agustin”,”403”,”503”,”903”);

INSERT INTO invoice VALUES


(“201”,”2024-01-04”,”340.00”,”Paid”,”101”,”501”,”901”),
(“202”,”2024-05-22”,”170.00”,”Unpaid”,”102”,”502”,”902”),
(“203”,”2024-05-23”,”510.00”,”Paid”,”103”,”503”,”903”);

INSERT INTO service VALUES


(“301”,”340.00”,”201”,”701”),
(“302”,”170.00”,”202”),
(“303”,510.00”,” 203”);

INSERT INTO payment VALUES


(“401”,”2024-01-04”,”340.00”,”501”),
(“402”,” ”,”170.00”,”502”),
(“403”,“2024-05-23”,”510.00”,”503”);

INSERT INTO payment_method VALUES


(“501”,” ”,” ”,”Paymaya”,”101”),
(“502”,”Cash”,” ”,” ”,”102),
(“503”,”Cash”,” ”,” ”,”103);

INSERT INTO tax VALUES


(“601”,”Abby Rose Basilan”,”15%”);

INSERT INTO user VALUES


(“701”,”Dona Delarmente”,”87654321”,”Employee”,”401”,”601”,”901”);

INSERT INTO billing_cycle VALUES


(“801”,”Dona Delarmente”,”8 Hours”,”701”,”101”);

INSERT INTO reminder VALUES


(“901”,”2024-01-04”,”Good day ma’am/sir your laundry is
done.”,”101”,”201”,”401”,”801”),
(“902”,”2024-05-22”,”Good day ma’am/sir your laundry is done.”,”102”,”202”,” 402“),
(“903”,”2024-05-23”,”Good day ma’am/sir your laundry is done.”,”103”,”203”,” 4023);

You might also like