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

New Text Document

The document creates databases and tables to store information about classes, subjects, students and student scores. It includes sample data and queries to demonstrate how to insert, update, select and join data from the tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

New Text Document

The document creates databases and tables to store information about classes, subjects, students and student scores. It includes sample data and queries to demonstrate how to insert, update, select and join data from the tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

create database QUANLYSINHVIEN

go
use QUANLYSINHVIEN
go
create table LOP
(
MALOP char(7) not null primary key,
TENLOP nvarchar(50) not null,
SISO tinyint not null,
check (SISO >0),
)
create table MONHOC
(
MAMONHOC char(7) not null primary key,
TENMONHOC nvarchar(50) not null,
TCLT tinyint not null,
TCTH tinyint not null,
check (TCLT >0),
check (TCTH >=0),
)
create table SINHVIEN
(
MASV char(6) not null primary key,
HOTEN nvarchar(50) not null,
NTNS date,
PHAI bit DEFAULT '1',
MALOP char(7) not null,
foreign key(MALOP) references LOP(MALOP)
on update cascade
on delete no action
)
create table DIEMSV
(
MASV char(6) not null ,
MAMONHOC char(7) not null,
DIEM decimal(3,1) check(DIEM between 0 and 10),
primary key(MASV,MAMONHOC),
foreign key(MASV) references SINHVIEN(MASV)
on update cascade
on delete no action,
foreign key(MAMONHOC) references MONHOC(MAMONHOC)
on update cascade
on delete no action
)
select * from LOP
select * from MONHOC
set dateformat DMY
--1
insert into SINHVIEN values(190001,N'Đào Thị Tuyết Hoa','08/03/2001',0,'19DTH02')
--2
UPDATE MONHOC
set TENMONHOC =N'Toán rời rạc'
where TENMONHOC =N'Lý thuyết đồ thị'
--3
SELECT TENMONHOC 'Tên môn học' FROM MONHOC WHERE TCTH= 0
--4
SELECT TENMONHOC 'Tên môn học' FROM MONHOC WHERE TCTH>=1 and TCLT>=1
--5
SELECT TENMONHOC 'Tên môn học' FROM MONHOC WHERE LEFT(TENMONHOC,1)='C'
--6
SELECT * FROM SINHVIEN WHERE HOTEN like N'%Thị%'
--7
SELECT TOP 2 * FROM LOP ORDER BY SISO DESC
--9
SELECT HOTEN 'Họ tên',NTNS, DATEDIFF(year,NTNS,getDATE()) AS Tuoi FROM SINHVIEN
WHERE DATEDIFF(year,NTNS,getDATE())>=20
--8
SELECT MASV,HOTEN,NTNS,PHAI FROM SINHVIEN group by MALOP
--10
SELECT TENMONHOC 'Tên môn học' FROM MONHOC a ,DIEMSV b where a.MAMONHOC=b.MAMONHOC
and b.DIEM is NULL
--11
SELECT MASV 'Mã',HOTEN 'Tên',TENMONHOC 'Môn',DIEM 'Điểm' FROM
SINHVIEN,MONHOC,DIEMSV where SINHVIEN.MASV='170001'

You might also like