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

Create Table Vendors1

The document contains SQL statements that create tables to store data about vendors, customers, products, orders, order items, and product notes. It also includes statements to insert sample data into the tables and queries to select data from the tables.

Uploaded by

shintanurul0
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)
18 views

Create Table Vendors1

The document contains SQL statements that create tables to store data about vendors, customers, products, orders, order items, and product notes. It also includes statements to insert sample data into the tables and queries to select data from the tables.

Uploaded by

shintanurul0
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/ 5

create table vendors(

vend_id char(4) not null primary key,

vend_name varchar(25) not null,

vend_address varchar(30),

vend_city varchar(20),

vend_state varchar(5),

vend_zip varchar(7),

vend_country varchar(15)

);

create table customers(

cust_id char(5) not null primary key,

cust_name varchar(25) not null,

cust_address varchar(30) null,

cust_city varchar(25) null,

cust_state varchar(5) null,

cust_zip varchar(5) null,

cust_country varchar(20) null,

cust_contact varchar(25) null,

cust_email varchar(30) null

);

create table products(

prod_id varchar(10) not null primary key,

vend_id char(4) not null,

prod_name varchar(25) not null,

prod_price int not null,

prod_desc varchar(255) null

);

create table orders(

order_num int not null,


order_date date not null,

cust_id char(5) not null,

primary key(order_num)

);

create table productnotes(

note_id char(3) not null,

prod_id varchar(10) not null,

note_date date not null,

note_text varchar(200) null,

primary key (note_id),

foreign key (prod_id)references products (prod_id)

);

create table orderitems(

order_num int not null,

order_item int not null,

prod_id varchar(10) not null,

quantity int not null,

primary key (order_num, order_item)

);

insert into customers(cust_id, cust_name, cust_address, cust_city, cust_state,

cust_zip, cust_country, cust_contact, cust_email)values

('1111','ananta','rowoyoso','wonokerto',

'IN','112','IN','0865000000','[email protected]');

insert into customers(cust_id, cust_name, cust_address, cust_city, cust_state,

cust_zip, cust_country, cust_contact, cust_email)values

('1112','fidya','karangjompo','tirto','IN','113',

'IN','0877000000','[email protected]');

insert into customers(cust_id, cust_name, cust_address, cust_city, cust_state,

cust_zip, cust_country, cust_contact, cust_email)values


('1113','sinta','bojongwetan','bojong',

'IN','114','IN','0823000000','[email protected]');

insert into customers(cust_id, cust_name, cust_address, cust_city, cust_state,

cust_zip, cust_country, cust_contact, cust_email)values

('1114','minkha','tanjung','tirto','IN','115','IN',

'0819000000','[email protected]');

insert into vendors(vend_id, vend_name, vend_address, vend_city, vend_state,

vend_zip, vend_country)values('1001','ramayana',

'123 pekalongan','pekalongan','IN','222','IN');

insert into vendors(vend_id, vend_name, vend_address, vend_city, vend_state,

vend_zip, vend_country)values('1002','transmart',

'500 pekalongan','pekalongan','IN','223','IN');

insert into vendors(vend_id, vend_name, vend_address, vend_city, vend_state,

vend_zip, vend_country)values('1003','yogya','555
pekalongan',

'pekalongan','IN','224','IN');

insert into vendors(vend_id, vend_name, vend_address, vend_city, vend_state,

vend_zip, vend_country)values('1004','matahari','1000
pekalongan',

'pekalongan','IN','225','IN');

insert into products(prod_id, vend_id, prod_name, prod_price, prod_desc)values

('CH01','1001','beras','60000','5 kg beras');

insert into products(prod_id, vend_id, prod_name, prod_price, prod_desc)values

('FT22','1001','minyak','100000','8 liter minyak');

insert into products(prod_id, vend_id, prod_name, prod_price, prod_desc)values

('GH91','1001','gula','150000','10 kg gula');

insert into products(prod_id, vend_id, prod_name, prod_price, prod_desc)values

('AD11','1003','shampo','15000','shampo');
insert into products(prod_id, vend_id, prod_name, prod_price, prod_desc)values

('AB','1003','sabun','10000','sabun deterjen');

insert into products(prod_id, vend_id, prod_name, prod_price, prod_desc)values

('FC','1003','garam','5000','garam dapur');

insert into products(prod_id, vend_id, prod_name, prod_price, prod_desc)values

('FU1','1004','teh','3000','teh tubruk');

insert into orders(order_num, order_date, cust_id)values

('20005','2024-01-01','1111');

insert into orders(order_num, order_date, cust_id)values

('20005','2024-01-01','1112');

insert into orders(order_num, order_date, cust_id)values

('20005','2024-01-01','1113');

insert into orders(order_num, order_date, cust_id)values

('20005','2024-01-01','1114');

insert into orders(order_num, order_date, cust_id)values

('20006','2024-01-02','1113');

insert into orders(order_num, order_date, cust_id)values

('20007','2024-01-02','1111');

insert into orders(order_num, order_date, cust_id)values

('20008','2024-01-03','1114');

insert into orderitems(order_num, order_item,prod_id,quantity)values('20005','1','CH01','10');

insert into orderitems(order_num, order_item,prod_id,quantity)values('20005','2','FT22','3');

insert into orderitems(order_num, order_item,prod_id,quantity)values('20005','3','GH91','5');

insert into orderitems(order_num, order_item,prod_id,quantity)values('20005','4','AD11','1');

insert into orderitems(order_num, order_item,prod_id,quantity)values('20006','1','AB','1');

insert into orderitems(order_num, order_item,prod_id,quantity)values('20007','1','FC','1');

insert into orderitems(order_num, order_item,prod_id,quantity)values('20008','1','FU1','5');

select*from customers order by cust_name asc;


select*from orderitems order by quantity desc;

select prod_name, prod_price from products order by prod_price asc;

select c.cust_name, c.cust_email, c.cust_contact from customers c join orders o

on c.cust_id=o.cust_id join orderitems oi on o.order_num=oi.order_num group by c.cust_id

order by sum(oi.quantity) desc;

select*from orders o join customers c on o.cust_id=c.cust_id where c.cust_name='ananta';

select*from orderitems oi join products p on oi.prod_id=p.prod_id join orders o

on oi.order_num=o.order_num where o.cust_id='1111';

CREATE VIEW order_details_view AS

SELECT o.order_num, o.order_date, c.cust_name, c.cust_email, p.prod_name, oi.quantity

FROM orders o JOIN customers c ON o.cust_id = c.cust_id JOIN orderitems oi

ON o.order_num = oi.order_num JOIN products p ON oi.prod_id = p.prod_id;

SELECT * FROM order_details_view;

You might also like