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

New SQL File

The document creates tables to store customer, product, invoice, and order details data with relevant columns and constraints. It inserts sample data into the tables to demonstrate their use for an online shopping database that tracks customers, products, orders and sales.

Uploaded by

Kanti Chaurasia
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

New SQL File

The document creates tables to store customer, product, invoice, and order details data with relevant columns and constraints. It inserts sample data into the tables to demonstrate their use for an online shopping database that tracks customers, products, orders and sales.

Uploaded by

Kanti Chaurasia
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE TABLE Customer(

Cust_Id INT PRIMARY KEY,


Cust_Name CHAR(20) NOT NULL,
Cust_Address CHAR(20) NOT NULL,
City CHAR(20) NOT NULL,
State VARCHAR(20) DEFAULT 'Maharashtra',
Email_id CHAR(20) NOT NULL,
Contact NUMERIC(10) UNIQUE
);

DESC Customer;
CREATE table Product(
Product_Id int Primary Key,
Product_Name char(20) Not null,
Product_type char(20) Not null,
Unit_Price char(20) Not null,
Qty char(20) default 0
);
DESC Product;

CREATE table Invoice(


Order_Id int Primary Key,
Order_Date date Not Null,
Cust_Id int,
Total_Qty char(20) default 0,
Total_Amount float(10,2) default 0,
FOREIGN KEY (Cust_Id) REFERENCES Customer(Cust_Id)
);
DESC invoice;

CREATE table Order_details(


Trans_Id int Primary Key,
Order_Id int,
Cust_Id int,
Product_Id int,
Unit_Price char(20) Not null,
Qty char(20) default 0,
Total_Amount float(10,2) default 0,
FOREIGN KEY (Order_Id) REFERENCES Invoice(Order_Id),
FOREIGN KEY (Cust_Id) REFERENCES Customer(Cust_Id),
FOREIGN KEY (Product_Id) REFERENCES Product(Product_Id)
);

INSERT INTO Customer(Cust_Id, Cust_Name, Cust_Address, City, Email_id, Contact)


VALUES(1,'Tom','sector 22','Mumbai','[email protected]', 9664329489);
INSERT INTO Customer(Cust_Id, Cust_Name, Cust_Address, City, Email_id, Contact)
VALUES(2,'Jerry','sector 1','Bihar','[email protected]', 6866594609);

INSERT INTO Product(Product_Id, Product_Name, Product_type, Unit_Price)


VALUES(101,'Maggi','Food',14);
INSERT INTO Product(Product_Id, Product_Name, Product_type, Unit_Price)
VALUES(102,'dairy milk','Food', 10);
INSERT INTO Product(Product_Id, Product_Name, Product_type, Unit_Price)
VALUES(103,'Amul Butter','Food',40);
INSERT INTO Product(Product_Id, Product_Name, Product_type, Unit_Price)
VALUES(104,'watch','Accessory', 2000);
INSERT INTO Product(Product_Id, Product_Name, Product_type, Unit_Price)
VALUES(105,'laptop','ELECTRONICS', 80000);
INSERT INTO Invoice(Order_Id, Order_Date, Cust_Id)
VALUES(11,'2022-18-12',1);
INSERT INTO Invoice(Order_Id, Order_Date, Cust_Id)
VALUES(32,'2022-07-08',2);
INSERT INTO Invoice(Order_Id, Order_Date, Cust_Id)
VALUES(34,'2021-04-03',2);
INSERT INTO Invoice(Order_Id, Order_Date, Cust_Id)
VALUES(21,'2022-06-02',1);

INSERT INTO Order_Details(Trans_Id, Order_Id, Cust_Id, Product_Id, Unit_Price, Qty)

VALUES(111,11,1,201,14,10);
INSERT INTO Order_Details(Trans_Id, Order_Id, Cust_Id, Product_Id, Unit_Price, Qty)
VALUES(222,34,2,202,40,4);
INSERT INTO Order_Details(Trans_Id, Order_Id, Cust_Id, Product_Id, Unit_Price, Qty)

VALUES(333,32,2,203,2000,1);
INSERT INTO Order_Details(Trans_Id, Order_Id, Cust_Id, Product_Id, Unit_Price, Qty)

VALUES(444,21,1,203,80000,1);

You might also like