CREATE DATABASE DKMH_1351010002_DH13TH ----create table MonHoc MaMH nvarchar10 primary key, TenMH nvarchar50 NOT NULL, SoTC int CHECK SoTC> create table Lop MaLop nchar10 primary key
Trang 1CREATE DATABASE DKMH_1351010002_DH13TH
create table MonHoc
(
MaMH nvarchar(10) primary key,
TenMH nvarchar(50) NOT NULL,
SoTC int CHECK (SoTC> )
)
create table Lop
(
MaLop nchar(10) primary key,
TenLop nvarchar(50) NOT NULL,
NganhHoc nvarchar(50) NOT NULL
)
create table SinhVien
(
MaSV nvarchar(10) primary key,
HoSV nvarchar(50) not null,
TenSV nvarchar(50) not null,
NgaySinh smalldatetime not null,
GioiTinh bit not null,
MaLop nchar(10) not null
Constraint FK_Lop Foreign key (MaLop)
References Lop(MaLop)
on delete cascade
on update cascade
)
create table DKMH
(
MaSV nvarchar(10) Not Null,
MaMH nvarchar(10) Not Null,
NgayDK smalldatetime,
Constraint PK_DKMH Primary key (MaSV, MaMH),
Constraint FK_MaSV Foreign key(MaSV) References SinhVien(MaSV)
on delete cascade
on update cascade,
Constraint FK_MaMH Foreign key(MaMH) References MonHoc(MaMH)
on delete cascade
on update cascade
)
-INSERT INTO MonHoc values ('MH1',N'Cơ sơ8 dữ liệu','3')
INSERT INTO MonHoc values ('MH2',N'Lập trình web','3')
INSERT INTO MonHoc values ('MH3',N'Phân tích thiếAt kếA hệ thốAng','3') INSERT INTO MonHoc values ('MH4',N'Lập trình windown','3')
INSERT INTO MonHoc values ('MH5',N'TiếAng anh 3','3')
-INSERT INTO Lop values ('DH13TH','IT','CNTT')
Trang 2INSERT INTO Lop values ('DH15TH','IT','CNTT')
INSERT INTO Lop values ('CD13TH','IT','CNTT')
INSERT INTO Lop values ('DH14TH','IT',N'Khoa hoc máy tính') INSERT INTO Lop values ('CD14TH','IT',N'Khoa hoc máy tính')
INSERT INTO DKMH values ('1351010002','MH1','9/7/2014') INSERT INTO DKMH values ('1351010003','MH1','9/7/2014') INSERT INTO DKMH values ('135101005','MH1','9/7/2014') INSERT INTO DKMH values ('135101008','MH1','9/7/2014') INSERT INTO DKMH values ('135101001','MH2','10/7/2014')
-INSERT INTO SinhVien values ('1351010002',N'Võ
Thanh',N'Bình','2/10/1994','1','DH13TH')
INSERT INTO SinhVien values ('1351010003',N'huỳnh
quốAc',N'cường','2/10/1994','1','DH13TH')
INSERT INTO SinhVien values ('135101005',N'Trương
ngọc',N'Toàn','3/4/1994','1','CD13TH')
INSERT INTO SinhVien values ('135101008',N'Võ
tâAn',N'Vương','1/12/1995','1','CD13TH')
INSERT INTO SinhVien values ('135101001',N'Võ
thanh',N'Hòa','1/12/1995','1','CD13TH')