Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
QLDT TUAN 6
CREATE TABLE GIAOVIEN( MAGV NCHAR(10), HOTEN NVARCHAR(30), LUONG INT, PHAI NCHAR(3), NGSINH DATETIME, DIACHI NVARCHAR(50), GVQLCM NCHAR(10), MABM NCHAR(10), PRIMARY KEY(MAGV) ); CREATE TABLE KHOA( MAKHOA NCHAR(10), TENKHOA NVARCHAR(30), NAMTL INT, PHONG NCHAR(10), DIENTHOAI INT, TRUONGKHOA NCHAR(10), NGAYNHAMCHUC DATETIME, PRIMARY KEY (MAKHOA) ); CREATE TABLE BOMON( MABM NCHAR(10), TENBM NVARCHAR(30), PHONG NCHAR(10), DIENTHOAI INT, TRUONGBM NCHAR(10), MAKHOA NCHAR(10), NGAYNHAMCHUC DATETIME, PRIMARY KEY (MABM) ); CREATE TABLE GV_DT( MAGV NCHAR(10), DIENTHOAI INT, PRIMARY KEY(MAGV, DIENTHOAI) ); CREATE TABLE NGUOITHAN( MAGV NCHAR(10), TEN NVARCHAR(30), NGSINH DATETIME, PHAI NCHAR(3), PRIMARY KEY (MAGV, TEN) ); CREATE TABLE CHUDE( MACD NCHAR(10), TENCD NVARCHAR(30), PRIMARY KEY(MACD) ); CREATE TABLE DETAI( MADT NCHAR(10), TENDT NVARCHAR(50), CAPQL NVARCHAR(20), KINHPHI INT, NGAYBD DATETIME, NGAYKT DATETIME, MACD NCHAR(10), GVCNDT NCHAR(10), PRIMARY KEY(MADT) ); CREATE TABLE CONGVIEC( MADT NCHAR(10), SOTT INT, TENCV NVARCHAR(40), NGAYBD DATETIME, NGAYKT DATETIME, PRIMARY KEY(MADT, SOTT) ); CREATE TABLE THAMGIADT( MAGV NCHAR(10), MADT NCHAR(10), SOTT INT, PHUCAP INT, KETQUA NVARCHAR(20), PRIMARY KEY(MAGV, MADT, SOTT) ); ALTER TABLE BOMON ADD CONSTRAINT FK_BOMON_KHOA FOREIGN KEY (MAKHOA) REFERENCES KHOA(MAKHOA) ALTER TABLE BOMON ADD CONSTRAINT FK_BOMON_GIAOVIEN FOREIGN KEY (TRUONGBM) REFERENCES GIAOVIEN(MAGV) ALTER TABLE GV_DT ADD CONSTRAINT FK_GV_DT_GIAOVIEN FOREIGN KEY (MAGV) REFERENCES GIAOVIEN(MAGV) ALTER TABLE NGUOITHAN ADD CONSTRAINT FK_NGUOITHAN_GIAOVIEN FOREIGN KEY (MAGV) REFERENCES GIAOVIEN(MAGV) ALTER TABLE KHOA ADD CONSTRAINT FK_KHOA_GIAOVIEN FOREIGN KEY (TRUONGKHOA) REFERENCES GIAOVIEN(MAGV) ALTER TABLE THAMGIADT ADD CONSTRAINT FK_THAMGIADT_GIAOVIEN FOREIGN KEY (MAGV) REFERENCES GIAOVIEN(MAGV) ALTER TABLE THAMGIADT ADD CONSTRAINT FK_THAMGIADT_CONGVIEC FOREIGN KEY (MADT, SOTT) REFERENCES CONGVIEC(MADT, SOTT) ALTER TABLE CONGVIEC ADD CONSTRAINT FK_CONGIVEC_DETAI FOREIGN KEY (MADT) REFERENCES DETAI(MADT) ALTER TABLE DETAI ADD CONSTRAINT FK_DETAI_CHUDE FOREIGN KEY (MACD) REFERENCES CHUDE(MACD) ALTER TABLE DETAI ADD CONSTRAINT FK_DETAI_GIAOVIEN FOREIGN KEY (GVCNDT) REFERENCES GIAOVIEN(MAGV) ALTER TABLE GIAOVIEN ADD CONSTRAINT FK_GIAOVIEN_GIAOVIEN FOREIGN KEY (GVQLCM) REFERENCES GIAOVIEN(MAGV) ALTER TABLE GIAOVIEN ADD CONSTRAINT FK_GIAOVIEN_BOMON FOREIGN KEY (MABM) REFERENCES BOMON(MABM) INSERT INTO GIAOVIEN VALUES ('001', 'NGUYEN HOAI AN', '2000', 'NAM', '2/15/1973', 'TP HCM', NULL, NULL), ('002', 'TRAN TRA HUONG', '2500', 'NU', '6/20/1960', 'TP HCM', NULL, NULL), ('003', 'NGUYEN NGOC ANH','2200','NU','5/11/1975','TP HCM', '002', NULL), ('004', 'TRUONG NAM SON', '2300', 'NAM', '6/20/1959', 'BIEN HOA', NULL, NULL), ('005', 'LY HOANG HA', '2500', 'NAM', '10/23/1954', 'TP HCM', NULL, NULL) INSERT INTO KHOA VALUES ('CNTT', 'CONG NGHE THONG TIN', '1995', 'B11', '0838123456', '002', '2/20/2005'), ('HH', 'HOA HOC', '1980', 'B41', '0838456456', '001', '10/15/2001'), ('SH', 'SINH HOC', '1980', 'B31', '083845454', '004', '10/11/2000'), ('VL', 'VAT LY', '1976', 'B21', '0838223223', '005', '9/18/2003') INSERT INTO BOMON VALUES ('CNTT', 'CONG NGHE TRI THUC', 'B15', '0838126126', NULL, 'CNTT', NULL), ('HHC', 'HOA HUC CO', 'B44', '0838222222', NULL, 'HH', NULL), ('HL', 'HOA LY', 'B42', '0838878787', NULL, 'HH', NULL), ('HPT', 'HOA PHAN TICH', 'B43', '0838777777', '001', 'HH', '10/15/2007'), ('HTTT', 'HE THONG THONG TIN', 'B13', '0838125125', '002', 'CNTT', '9/20/2004') INSERT INTO NGUOITHAN VALUES ('001', 'HUNG', '1/14/1990', 'NAM'), ('001', 'THUY', '12/8/1994', 'NU'), ('003', 'HA', '9/3/1998', 'NU'), ('003', 'THU', '9/3/1998', 'NU') INSERT INTO GV_DT VALUES ('001', '0838912112'), ('001', '0903123123'), ('002', '0913454545'), ('003', '0838121212'), ('003', '0903656565') INSERT INTO CHUDE VALUES ('NCPT', 'NGHIEN CUU PHAT TRIEN'), ('QLGD', 'QUAN LY GIAO DUC'), ('UDCN', 'UNG DUNG CONG NGHE') INSERT INTO DETAI VALUES ('001', 'HTTT QUAN LY CAC TRUONG DAI HOC', 'DHQG', '20', '10/20/2007', '10/20/2008', 'QLGD', '002'), ('002', 'HTTT QUAN LY GIAO VU CHO 1 KHOA', 'TRUONG', '20', '10/12/2000', '10/12/2001', 'QLGD', '002'), ('003', 'NGHIEN CUU CHE TAO SOI NANO PLATIN', 'DHQG', '300', '5/15/2008', '5/15/2010', 'NCPT', '005'), ('004', 'TAO VAT LIEU SINH HOC BANG MANG OI NGUOI', 'NHA NUOC', '100','1/1/2007', '12/31/2009', 'NCPT', '004'), ('005', 'UNG DUNG HOA HOC XANH', 'TRUONG', '200', '10/10/2003', '12/10/2004', 'UDCN', '001') INSERT INTO CONGVIEC VALUES ('001', '1', 'KHOI TAO VA LAP KE HOACH', '10/20/2007', '12/20/2008'), ('001', '2', 'XAC DINH YEU CAU', '12/21/2008', '3/21/2008'), ('001', '3', 'PHAN TICH HE THONG', '3/22/2008', '5/22/2008'), ('001', '4', 'THIET KE HE THONG', '5/23/2008', '6/23/2008'), ('001', '5', 'CAI DAT THU NGHIEM', '6/24/2008', '10/20/2008'), ('002', '1', 'KHOI TAO VA LAP KE HOACH', '5/10/2009', '7/10/2009'), ('002', '2', 'XAC DINH YEU CAU', '7/11/2009', '10/11/2009'), ('002', '3', 'PHAN TICH HE THONG', '10/12/2009', '12/20/2009'), ('002', '4', 'THIET KE HE THONG', '12/21/2009', '3/22/2010'), ('002', '5', 'CAI DAT THU NGHIEM', '3/23/2010', '5/10/2010') INSERT INTO THAMGIADT VALUES ('001', '002', '1', '0', NULL), ('001', '002', '2', '2', NULL), ('002', '001', '4', '2', 'DAT'), ('003', '001', '1', '1', 'DAT'), ('003', '001', '2', '0', 'DAT') UPDATE GIAOVIEN SET MABM='CNTT' WHERE MAGV='001'; UPDATE GIAOVIEN SET MABM='HTTT' WHERE MAGV='002'; UPDATE GIAOVIEN SET MABM='HTTT' WHERE MAGV='003'; UPDATE GIAOVIEN SET MABM='CNTT' WHERE MAGV='004'; UPDATE GIAOVIEN SET MABM='HL' WHERE MAGV='005'; SELECT DISTINCT TG1.MAGV FROM THAMGIADT TG1 WHERE NOT EXISTS (SELECT MADT FROM DETAI EXCEPT (SELECT TG2.MADT FROM THAMGIADT TG2 WHERE TG2.MAGV = TG1.MAGV)) SELECT HOTEN FROM GIAOVIEN GV, DETAI DT, CHUDE CD, THAMGIADT TG WHERE GV.MAGV = TG.MAGV AND TG.MADT = DT.MADT AND DT.MACD = CD.MACD GROUP BY HOTEN, GV.MAGV HAVING COUNT(DISTINCT CD.MACD) = (SELECT COUNT(*) FROM CHUDE) SELECT TENDT FROM DETAI DT1, THAMGIADT TG1, GIAOVIEN GV1, BOMON BM1 WHERE TG1.MADT = DT1.MADT AND TG1.MAGV = GV1.MAGV AND GV1.MABM = BM1.MABM AND BM1.TENBM = 'HE THONG THONG TIN' GROUP BY TENDT HAVING COUNT(*) = (SELECT COUNT(*) FROM GIAOVIEN GV2, BOMON BM2 WHERE GV2.MABM = BM2.MABM AND BM2.TENBM = 'HE THONG THONG TIN') SELECT HOTEN FROM GIAOVIEN GV, THAMGIADT TG, DETAI DT WHERE GV.MAGV = TG.MAGV AND TG.MADT = DT.MADT AND DT.MACD = 'QLGD' GROUP BY HOTEN HAVING COUNT(DISTINCT TG.MADT) = (SELECT COUNT(*) FROM DETAI WHERE MACD = 'QLGD') SELECT DISTINCT HOTEN FROM GIAOVIEN GV, THAMGIADT TG WHERE GV.MAGV = TG.MAGV AND GV.HOTEN != 'TRAN TRA HUONG' AND NOT EXISTS (SELECT TG1.MADT FROM THAMGIADT TG1, GIAOVIEN GV1 WHERE TG1.MAGV = GV1.MAGV AND GV1.HOTEN = 'TRAN TRA HUONG' EXCEPT ( SELECT TG2.MADT FROM THAMGIADT TG2 WHERE TG.MAGV = TG2.MAGV))
run
|
edit
|
history
|
help
0
Using pre-built schema in sql server
islands and gaps problem
hhzn
bc160402152
Suikwan tests
BC160401693
manual app locks
Negociosj
Unpivot Example
Task_6_Final