0% found this document useful (0 votes)
10 views

SQL Code

Uploaded by

psmanian36
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)
10 views

SQL Code

Uploaded by

psmanian36
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/ 2

CREATE DATABASE billing_system;

USE billing_system;

-- Table to store product information

CREATE TABLE products (

product_id INT AUTO_INCREMENT PRIMARY KEY,

name VARCHAR(100) NOT NULL,

description TEXT,

price DECIMAL(10, 2) NOT NULL,

stock_quantity INT NOT NULL

);

-- Table to store customer information

CREATE TABLE customers (

customer_id INT AUTO_INCREMENT PRIMARY KEY,

name VARCHAR(100) NOT NULL,

email VARCHAR(100) UNIQUE NOT NULL,

phone VARCHAR(20),

address TEXT

);

-- Table to store billing transactions

CREATE TABLE bills (

bill_id INT AUTO_INCREMENT PRIMARY KEY,

customer_id INT NOT NULL,

bill_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

total_amount DECIMAL(10, 2) NOT NULL,

payment_status ENUM('Paid', 'Pending') DEFAULT 'Pending',

FOREIGN KEY (customer_id) REFERENCES customers(customer_id)

);
-- Table to store products included in the bill

CREATE TABLE bill_items (

bill_item_id INT AUTO_INCREMENT PRIMARY KEY,

bill_id INT NOT NULL,

product_id INT NOT NULL,

quantity INT NOT NULL,

price DECIMAL(10, 2) NOT NULL,

FOREIGN KEY (bill_id) REFERENCES bills(bill_id),

FOREIGN KEY (product_id) REFERENCES products(product_id)

);

You might also like