CarlsonJingga - Kelas S - UAS

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

1.

create table Customers(


customer_id INT PRIMARY KEY NOT NULL,
customer_name VARCHAR(30) NOT NULL);

describe * customers;

create table Orders(


order_id INT PRIMARY KEY NOT NULL, customer_id INT NOT NULL,
order_date DATE NOT NULL,
CONSTRAINT fk_customer FOREIGN KEY (customer_id) REFERENCES
Customers(customer_id));

describe * orders;

create table Shipments(


shipment_id INT PRIMARY KEY NOT NULL,
order_id INT NOT NULL,
shipment_date DATE NOT NULL,
CONSTRAINT fk_order FOREIGN KEY (order_id) REFERENCES Orders(order_id));

describe * shipments;

create table Products(


product_id INT PRIMARY KEY NOT NULL,
merk VARCHAR2(30) NOT NULL,
price INT NOT NULL);

describe * products;

create table Order_Detail(


order_id INT NOT NULL REFERENCES Orders(order_id),
product_id INT NOT NULL REFERENCES Products(product_id),
sum_of_order INT NOT NULL,
comments VARCHAR2(30),
PRIMARY KEY(order_id, product_id));

describe * order_detail;

2.insert into customers (customer_id, customer_name)


values ('101', 'John');
insert into customers (customer_id, customer_name)
values ('102', 'Ryan');
insert into customers (customer_id, customer_name)
values ('103', 'Susan');
insert into customers (customer_id, customer_name)
values ('104', 'Donna');
insert into customers (customer_id, customer_name)
values ('105', 'Patrick');
select*from Customers;

insert into products (product_id, merk, price)


values('222', 'Toshiba', '25000');
insert into products (product_id, merk, price)
values('223', 'Mito', '45700');
insert into products (product_id, merk, price)
values('224', 'Sanken', '35000');
insert into products (product_id, merk, price)
values('225', 'Sony', '53500');
insert into products (product_id, merk, price)
values('221', 'Toshiba', '53500');
SELECT * from products;

insert into orders (order_id, customer_id, order_date)


values('704', '105', '15-Jan-2022');
insert into orders (order_id, customer_id, order_date)
values('705', '103', '30-Oct-2022');
insert into orders (order_id, customer_id, order_date)
values('700', '101', '15-Jan-2022');
insert into orders (order_id, customer_id, order_date)
values('701', '101', '25-Mar-2022');
insert into orders (order_id, customer_id, order_date)
values('702', '103', '13-Apr-2022');
insert into orders (order_id, customer_id, order_date)
values('703', '104', '20-Jan-2022');
insert into orders (order_id, customer_id, order_date)
values('706', '104', '15-Jan-2022');
select * from orders;

insert into shipments (shipment_id, order_id, shipment_date)


values('12', '700', '17-Jan-2022');
insert into shipments (shipment_id, order_id, shipment_date)
values('13', '701', '28-Mar-2022');
insert into shipments (shipment_id, order_id, shipment_date)
values('14', '702', '17-Apr-2022');
insert into shipments (shipment_id, order_id, shipment_date)
values('15', '703', '24-Jan-2022');
insert into shipments (shipment_id, order_id, shipment_date)
values('16', '704', '17-Jan-2022');
insert into shipments (shipment_id, order_id, shipment_date)
values('17', '705', '02-Nov-2022');
insert into shipments (shipment_id, order_id, shipment_date)
values('18', '706', '18-Jan-2022');
select * from shipments;

insert into order_detail(order_id, product_id, sum_of_order, comments)


values('705', '222', '4', 'null');
insert into order_detail(order_id, product_id, sum_of_order, comments)
values('706', '225', '3', 'shipment at noon');
insert into order_detail(order_id, product_id, sum_of_order, comments)
values('700', '222', '2', 'as order');
insert into order_detail(order_id, product_id, sum_of_order, comments)
values('700', '225', '1', 'as order');
insert into order_detail(order_id, product_id, sum_of_order, comments)
values('701', '221', '5', 'shipment on office hour');
insert into order_detail(order_id, product_id, sum_of_order, comments)
values('701', '225', '3', '-');
insert into order_detail(order_id, product_id, sum_of_order, comments)
values('702', '222', '12', 'as order');
insert into order_detail(order_id, product_id, sum_of_order, comments)
values('703', '224', '6', '-');
insert into order_detail(order_id, product_id, sum_of_order, comments)
values('704', '221', '1', 'shipment at night');
select * from order_detail;

3.update shipments set shipment_date = to_date('2022-11-03', 'YYY-MM-DD')


where shipment_id = '17';
select * from shipments;
4.select p.product_id, count(o.order_id) as "number of sales"
from products p, orders o
where p.merk = 'SONY'
group by p.product_id;

5.select p.product_id, p.merk, od.sum_of_order as "quantity"


from products p
inner join order_detail od ON p.product_id = od.product_id
inner join orders o ON od.order_id = o.order_id
where o.customer_id = '&input';

6.alter table customers


add CITY varchar2(20) constraint city_constraint check (city in ('JAKARTA',
'BOGOR', 'SURABAYA'));
describe customers;

select CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, SEARCH_CONDITION


from user_constraints
where table_name = 'CUSTOMERS';

7.select po.product_id, po.price, od.sum_of_order AS "quantity", (po.price *


od.sum_of_order)
AS "total of selling"
from products po
INNER JOIN order_detail od ON po.product_id = od.product_id;

8.CREATE VIEW SALES_DETAILS AS


SELECT orders.order_id, orders.order_date, Customers.customer_name,
Shipments.shipment_date
FROM orders,shipments,customers
WHERE orders.customer_id = customers.customer_id AND orders.order_id =
shipments.order_id;

SELECT * FROM SALES_DETAILS;

9 a. hal tersebut dapat dilakukan karena product_id dengan id=224 ada di dalam
tabel product
b.DELETE FROM products WHERE product_id = 224;

You might also like