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

Use Tuan1

The document creates tables to store product, laptop, PC, and printer data in a database. It defines the structure of each table including primary keys, foreign keys, and data types of columns. Data is then inserted into each table with values for the different attributes. Several queries are written to select data from the tables based on certain conditions.

Uploaded by

dungbn89
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Use Tuan1

The document creates tables to store product, laptop, PC, and printer data in a database. It defines the structure of each table including primary keys, foreign keys, and data types of columns. Data is then inserted into each table with values for the different attributes. Several queries are written to select data from the tables based on certain conditions.

Uploaded by

dungbn89
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

use Tuan1 create table product ( maker char(1), model varchar(4) primary key, type varchar(7) ) create table

laptop ( code int primary key, model varchar(4)constraint FK_laptop foreign key(model) references product(model), speed decimal(4,0) not null, ram decimal(4,0) not null, hd decimal(3,0) not null, price float, screen int not null ) create table pc ( code int primary key, model varchar(4) constraint FK_pc foreign key(model) references product(model), speed decimal(4,0) not null, ram decimal(4,0) not null, hd decimal(3,0)not null, cd varchar(30)not null, price float ) create table printer ( code int primary key, model varchar(4) constraint FK_printer foreign key(model) references product(model), color char(1) not null, type char(6)not null, price float ) insert insert insert insert insert insert insert insert into into into into into into into into product(maker,model,type) product(maker,model,type) product(maker,model,type) product(maker,model,type) product(maker,model,type) product(maker,model,type) product(maker,model,type) product(maker,model,type) values('A','1111','PC') values('A','1112','PC') values('B','1113','Printer') values('B','1114','Printer') values('C','1115','Laptop') values('C','1116','Laptop') values('A','1117','Laptop') values('A','1118','PC')

insert into laptop(code,model,speed,ram,hd,screen,price) values(1,'1115',350,128,4.0,12,700.000) insert into laptop(code,model,speed,ram,hd,screen,price) values(2,'1116',380,128,4.0,14,750.000) insert into laptop(code,model,speed,ram,hd,screen,price) values(3,'1117',350,168,4.0,12,600.000) insert into pc(code,model,speed,ram,hd,cd,price) values(2,'1111',350,168,4.0,'12x',600.000)

insert into pc(code,model,speed,ram,hd,cd,price) values(1,'1112',350,168,4.0,'12x',500.000) insert into pc(code,model,speed,ram,hd,cd,price) values(4,'1118',350,168,4.0,'12x',550.000) insert into printer(code,model,color,type,price) values(1,'1113','y','laser',550.000) insert into printer(code,model,color,type,price) values(2,'1114','n','jet',550.000) select * from product select * from bang1 order by col1 collate SQL_Latin1_General_Cp1_CS_AS --hien thi tat ca cac may Pc co gia >500 select * from pc where price>=500.000 --hien thi tat ca cac nha san xuat may in co trong csdl select type from printer group by type -- hien thi tat ca cac PC,Laptop co gia >400 select pc.model,pc.speed,pc.price as PricePC, laptop.model,laptop.speed,laptop.price as PriceLaptop from pc,laptop where pc.price>=400000 and laptop.price>=400000 --hien thi cac may in mau select * from printer where color like 'y' --hien thi tat ca cac may pc o CD co toc do 12x hoac 24x va co gia <600 select * from pc where (cd like '12x' or cd like '24x') and price <600000 -- hien thi ten nha san xuat,toc do cpu,gia cua tat ca cac may PC co o cung <=10G select product.maker,pc.speed,pc.price from product,pc where pc.hd>=10 and product.type like 'PC' --hien thi

You might also like