BTH số 9 Vũ Hoàng Anh - 20021492

You might also like

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

Bài thực hành số 9

Vũ Hoàng Anh_20021492
Câu 1 : Thực hành các lệnh INSERT, UPDATE và DELETE trên các bảng
trong hình dưới đây của CSDL classicmodels.
 NSERT INTO productlines (productLine, textDescription)
VALUES (‘Iphone 10’, ‘FRAGILE, PLEASE HANDLE WITH CARE’);
INSERT INTO productlines (productLine, textDescription)
VALUES (‘Iphone 11’, ‘FRAGILE, PLEASE HANDLE WITH CARE’);
INSERT INTO productlines (productLine, textDescription)
VALUES (‘Iphone 11 Plus’, ‘SALE OF 25%’);

UPDATE productlines
SET textDescription = “OUT OF ORDER”
WHERE productLine = ‘Iphone 11’;

DELETE FROM productlines


WHERE productLine = ‘Iphone 10’;

 products
INSERT INTO products
(productCode, productName, productLine, productScale,
productVendor, productDescription, quantityInStock, buyPrice)
VALUES (‘S101’, ‘Telephone’, ‘Iphone 10’, ‘1:1’, ‘PRO’, ‘None’, 5, 1000);
INSERT INTO products
(productCode, productName, productLine, productScale,
productVendor, productDescription, quantityInStock, buyPrice)
VALUES (‘S102’, ‘Telephone’, ‘Iphone 11’, ‘1:1’, ‘PRO’, ‘None’, 3, 1500);
INSERT INTO products
(productCode, productName, productLine, productScale,
productVendor, productDescription, quantityInStock, buyPrice)
VALUES (‘S103’, ‘Telephone’, ‘Iphone 11 Plus’, ‘1:1’, ‘PRO’, ‘None’, 4, 2000);

UPDATE products
SET quantityStock = ‘6’
WHERE productCode = ‘S102’;

DELETE FROM products


WHERE productCode = ‘S103’;

 orders
INSERT INTO orders (orderNumber, orderDate, requiredDate, shippedDate, status,
comments, customerNumber )
VALUES (1, ‘2020-05-13’, ‘2020-05-25’, ‘2020-05-20’, ‘Shipped’, null, 11 );
INSERT INTO orders (orderNumber, orderDate, requiredDate, shippedDate, status,
comments, customerNumber )
VALUES (2, ‘2020-06-13’, ‘2020-05-27’, ‘2020-05-19’, ‘Cancel’, null, 12 );
INSERT INTO orders (orderNumber, orderDate, requiredDate, shippedDate, status,
comments, customerNumber )
VALUES (3, ‘2020-07-13’, ‘2020-05-24’, ‘2020-05-18’, ‘Shipped’, null, 13 );

UPDATE orders
SET status = ‘Cancel’
WHERE orderNumber = 3;

DELETE FROM orders


WHERE orderNumber = 1 ;

 orderdetails
INSERT INTO orderdetails (orderNumber, productCode, quantityOrdered, priceEach,
orderLineNumber)
VALUES (‘1’, ‘S101′, ’10’, ‘500’, ‘6’);
INSERT INTO orderdetails (orderNumber, productCode, quantityOrdered, priceEach,
orderLineNumber)
VALUES (‘2’, ‘S102’, ‘9’, ‘265’, ‘7’);
INSERT INTO orderdetails (orderNumber, productCode, quantityOrdered, priceEach,
orderLineNumber)
VALUES (‘3’, ‘S103′, ’11’, ‘300’, ‘8’);

UPDATE orderdetails
SET priceEach = ‘501’
WHERE orderNumber = ‘1’;

DELETE FROM orderdetails


WHERE orderNumber = ‘3’;
Câu 2 : Tạo một bảng đặt tên là temp_orderdetails, sau đó thực hiện thêm
dữ liệu trong ngày gần đây nhất từ bảng orderdetails vào bảng trên

 CREATE TABLE temp_orderdetails (


orderNumber INT(11),
productCode VARCHAR(15),
quantityOrdered INT(11),
priceEach DOUBLE,
orderLineNumber SMALLINT(6),
CONSTRAINT temp_pk PRIMARY KEY (orderNumber, productCode));

INSERT INTO temp_orderdetails


SELECT classicmodels.orderdetails.*
FROM classicmodels.orderdetails
INNER JOIN classicmodels.orders on orderdetails.orderNumber = orders.orderNumber
WHERE orders.orderDate = (SELECT MAX(orders.orderDate) FROM orders);

Câu 3 : Sửa các nhân viên có titleJob là ‘Sales Rep’ thành ‘Sales
Representative’

USE classicmodels;
UPDATE employees
SET jobTitle = ‘Sales Representative’
WHERE jobTitle = ‘Sales Rep’;

You might also like