0% found this document useful (0 votes)
2 views2 pages

Create Table Product

The document defines a database schema with three tables: Product, PC, Laptop, and Printer, each with specific attributes and foreign key relationships. It includes SQL commands to create these tables and insert various product entries with details such as model, specifications, and prices. The data covers different types of products from various makers, including PCs, laptops, and printers.

Uploaded by

Tiến Anh Bùi
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)
2 views2 pages

Create Table Product

The document defines a database schema with three tables: Product, PC, Laptop, and Printer, each with specific attributes and foreign key relationships. It includes SQL commands to create these tables and insert various product entries with details such as model, specifications, and prices. The data covers different types of products from various makers, including PCs, laptops, and printers.

Uploaded by

Tiến Anh Bùi
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/ 2

CREATE TABLE Product (

maker CHAR(1),
model INT PRIMARY KEY,
type VARCHAR(20)
);

CREATE TABLE PC (
model INT PRIMARY KEY,
speed FLOAT, -- GHz
ram INT, -- MB
hd INT, -- GB
price DECIMAL(10,2),
FOREIGN KEY (model) REFERENCES Product(model)
);

CREATE TABLE Laptop (


model INT PRIMARY KEY,
speed FLOAT, -- GHz
ram INT, -- MB
hd INT, -- GB
screen FLOAT, -- inch
price DECIMAL(10,2),
FOREIGN KEY (model) REFERENCES Product(model)
);

CREATE TABLE Printer (


model INT PRIMARY KEY,
color CHAR(1), -- 'Y' or 'N'
type VARCHAR(30), -- ví dụ: 'laser', 'ink-jet',...
price DECIMAL(10,2),
FOREIGN KEY (model) REFERENCES Product(model)
);
INSERT INTO Product (maker, model, type) VALUES
('A', 1001, 'pc'),
('A', 1002, 'pc'),
('A', 1003, 'pc'),
('A', 2004, 'laptop'),
('A', 2005, 'laptop'),
('A', 2006, 'laptop'),
('B', 1004, 'pc'),
('B', 1005, 'pc'),
('B', 1006, 'pc'),
('B', 2007, 'laptop'),
('C', 1007, 'pc'),
('D', 1008, 'pc'),
('D', 1009, 'pc'),
('D', 1010, 'pc'),
('D', 3004, 'printer'),
('D', 3005, 'printer'),
('E', 1011, 'pc'),
('E', 1012, 'pc'),
('E', 1013, 'pc'),
('E', 2001, 'laptop'),
('E', 2002, 'laptop'),
('E', 2003, 'laptop'),
('E', 3001, 'printer'),
('E', 3002, 'printer'),
('E', 3003, 'printer'),
('F', 2008, 'laptop'),
('F', 2009, 'laptop'),
('G', 2010, 'laptop'),
('H', 3006, 'printer'),
('H', 3007, 'printer');
INSERT INTO PC (model, speed, ram, hd, price) VALUES
(1001, 2.66, 1024, 250, 2114),
(1002, 2.1, 512, 250, 995),
(1003, 1.42, 512, 80, 478),
(1004, 2.8, 1024, 250, 649),
(1005, 3.2, 512, 250, 630),
(1006, 3.2, 1024, 320, 1049),
(1007, 2.2, 1024, 200, 510),
(1008, 2.2, 2048, 250, 770),
(1009, 2.0, 1024, 250, 650),
(1010, 2.8, 2048, 300, 770),
(1011, 1.86, 2048, 160, 959),
(1012, 2.8, 1024, 160, 649),
(1013, 3.06, 512, 80, 529);
INSERT INTO Laptop (model, speed, ram, hd, screen, price) VALUES
(2001, 2.0, 2048, 240, 20.1, 3673),
(2002, 1.73, 1024, 80, 17.0, 949),
(2003, 1.8, 512, 60, 15.4, 549),
(2004, 2.0, 512, 60, 13.3, 1150),
(2005, 2.16, 1024, 120, 17.0, 2500),
(2006, 2.0, 2048, 80, 15.4, 1700),
(2007, 1.83, 1024, 120, 13.3, 1429),
(2008, 1.6, 1024, 100, 15.4, 900),
(2009, 1.6, 512, 80, 14.1, 680),
(2010, 2.0, 2048, 160, 15.4, 2300);
INSERT INTO Printer (model, color, type, price) VALUES
(3001, 'Y', 'ink-jet', 99),
(3002, 'N', 'laser', 239),
(3003, 'Y', 'laser', 899),
(3004, 'Y', 'ink-jet', 120),
(3005, 'N', 'laser', 120),
(3006, 'Y', 'ink-jet', 100),
(3007, 'Y', 'laser', 200);

You might also like