Buoi4 SQL
Buoi4 SQL
--Cau 3
update Khuvuc set tang='0' where IP='130.120.80';
update Khuvuc set tang='1' where IP='130.120.81';
update Khuvuc set tang='2' where IP='130.120.82';
--Cau 4
update Phanmem set gia=gia-0.1*gia where idloai='PCNT';
--Cau 5
-- Thêm cOt nbLog vào bAng Máy
alter table May add nbLog smallint ;
update May set nbLog=0 where idMay='p1';
update May set nbLog=2 where idMay='p2';
update May set nbLog=0 where idMay='p3';
update May set nbLog=1 where idMay='p4';
update May set nbLog=0 where idMay='p5';
update May set nbLog=2 where idMay='p6';
update May set nbLog=1 where idMay='p7';
update May set nbLog=2 where idMay='p8';
update May set nbLog=0 where idMay='p9';
update May set nbLog=0 where idMay='p10';
update May set nbLog=2 where idMay='p11';
update May set nbLog=1 where idMay='p12';
-- Cau 6
create table PhanmemUNIX(
idPM varchar(10) ,
tenPM varchar(30) not null,
ngaymua date,
version varchar(5) not null
);
-- Cau 7
alter table PhanmemUNIX add primary key(idPM);
--Cau 8
alter table PhanmemUNIX add gia int;
-- Cau 9
alter table PhanmemUNIX modify version varchar(15);
--Cau 10
alter table PhanmemUNIX add unique (tenPM);
-- Cau 11
insert into PhanmemUNIX(idPM,tenPM,ngaymua,version,gia) select
idPM,tenPM,ngaymua,version,gia from Phanmem;
--Cau 12
alter table PhanmemUNIX drop column version;
--CAU 13
delete from Phanmem where gia>5000; -- Xóa không duoc vì nó có tham chieu khóa ngoai
la idloai
--Cau 14
delete from PhanmemUNIX where gia>5000; -- Xóa duoc vì nó không có tham chieu khóa
ngo?i
--Cau 15
drop table Phanmem; -- xóa không duoc vì khóa duy nhat/chính trong bang duoc tham chieu
bang khóa ngoai
-- Cau 16
drop table PhanmemUNIX; -- xóa duoc vì không tham chieu khóa ngo?i
--Cau 17
alter table May drop column nbLog;
alter table Phanmem drop column nbInstall;