

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Thuc Hanh CSDL Bai 1: Cau 3: CREATE DATABASE my_database; SHOW DATABASES;
Cau4: C:\AppServ\MySQL\data
Cau5: DROP DATABASE my_database;
Bai 2: Cau 1 và cau 2 (da ket hop rang buoc khoa ngoai giua cac bang) CREATE DATABASE my_classicmodels; CREATE TABLE productlines ( productLine VARCHAR(50) NOT NULL PRIMARY KEY, textDescription VARCHAR(50) NOT NULL, htmlDescription MEDIUMTEXT NOT NULL, image MEDIUMBLOB NOT NULL, );
CREATE TABLE products( productCode VARCHAR(15) NOT NULL PRIMARY KEY, productName VARCHAR(70) NOT NULL, productLine VARCHAR(50) NOT NULL, productScale VARCHAR(10) NOT NULL, productVendor VARCHAR(50) NOT NULL, productDescription TEXT NOT NULL, quantityInStock SMALLINT(6)NOT NULL, buyPrice DOUBLE NOT NULL,
CONSTRAINT fk_products_productlines FOREIGN KEY (productLine) REFERENCES productlines (productLine) ON DELETE RESTRICT );
CREATE TABLE orderdetails( orderNumber INT(11) NOT NULL AUTO_INCREMENT, productCode VARCHAR(15) NOT NULL, quantityOrdered INT(11) NOT NULL, priceEach DOUBLE NOT NULL, orderLineNumber SMALLINT(6) NOT NULL,
PRIMARY KEY (orderNumber, productCode),
CONSTRAINT fk_orderdetails_products FOREIGN KEY (productCode) REFERENCES products (productCode) ON DELETE RESTRICT ON UPDATE CASCADE );
CREATE TABLE orders( orderNumber INT(11) NOTNULL AUTO_INCREMENT PRIMARY KEY,
orderDate DATETIME, requireDate DATETIME, shippedDate DATETIME, status VARCHAR(15) NOT NULL, comments TEXT, customerNumber INT(11) NOT NULL,
CONSTRAINT fk_orders_orderdetails FOREIGN KEY (orderNumber) REFERENCES products (orderNumber) ON DELETE RESTRICT ON UPDATE CASCADE );