0% found this document useful (0 votes)
14 views3 pages

Hoc SQL

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
14 views3 pages

Hoc SQL

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 3

/****** Tạo bảng QuanLyBanHang ******/

CREAT DATABASE QuanLyBanHang


USE QuanLyBanHang
CREATE TABLE KHACHHANG
(
MAKH char(4) primary key,
HOTEN varchar(40),
DCHI varchar(50),
SODT varchar(20),
NGSINH smalldatetime,
DOANHSO money,
NGDK smalldatetime
)
CREATE TABLE NHANVIEN
(
MANV char(4) primary key,
HOTEN varchar(40),
NGVL varchar(20),
SODT smalldatetime
)
CREATE TABLE SANPHAM
(
MASP char(4) primary key,
TENSP varchar(40),
DVT varchar(20),
NUOCSX varchar(40),
GIA money
)
CREATE TABLE HOADON
(
SOHD int primary key,
NGHD smalldatetime,
MAKH char(4),
MANV char(4),
TRIGIA money
)
CREATE TABLE CTHD
(
SOHD int primary key,
MASP char(4),
SL int
)
ALTER TABLE HOADON ADD
CONSTRAINT HD_MAKH_FK FOREIGN KEY (MAKH) REFERENCES KHACHHANG(MAKH),
CONSTRAINT HD_MANV_FK FOREIGN KEY (MANV) REFERENCES NHANVIEN(MANV)
ALTER TABLE CTHD ADD
CONSTRAINT CTHD_MASP_FK FOREIGN KEY (MASP) REFERENCES SANPHAM(MASP),
CONSTRAINT CTHD_SOHD_FK FOREIGN KEY (SOHD) REFERENCES HOADON(SOHD)

/****** Tạo bảng QuanLyGiaoVu ******/


/****** Tạo bảng QuanLyGiaoVu ******/
/****** Tạo bảng QuanLyGiaoVu ******/
/****** Tạo bảng QuanLyGiaoVu ******/
/****** Tạo bảng QuanLyGiaoVu ******/

CREAT DATABASE QuanLyGiaoVu


USE QuanLyGiaoVu
CREATE TABLE KHOA
(
MAKHOA varchar(4) primary key,
TENKHOA varchar(40),
NGTLAP smalldatetime,
TRGKHOA char(4)
)
CREATE TABLE MONHOC
(
MAMH varchar(10) primary key,
TENMH varchar(40),
TCLT TINYINT,
TCTH TINYINT,
MAKHOA varchar(4) REFERENCES KHOA(MAKHOA)
)
CREATE TABLE DIEUKIEN
(
MAMH varchar(10) REFERENCES MONHOC(MAMH),
MAMH_TRUOC varchar(10) REFERENCES MONHOC(MAMH)
)
CREATE TABLE GIAOVIEN
(
MAGV char(4) primary key,
HOTEN varchar(40),
HOCVI varchar(10),
HOCHAM varchar(10),
GIOITINH varchar(3),
NGSINH smalldatetime,
NGVL smalldatetime,
HESO numeric(4,2),
MUCLUONG money,
MAKHOA varchar(4) REFERENCES KHOA(MAKHOA)
)
CREATE TABLE LOP
(
MALOP char(3) primary key,
TENLOP varchar(40),
TRGLOP char(5),
SISO TINYINT,
MAGVCN char(4)
)
CREATE TABLE HOCVIEN
(
MAHV char(5) primary key,
HO varchar(40),
TEN varchar(10),
NGSINH smalldatetime,
GIOITINH varchar(3),
NOISINH varchar(40),
MALOP char(3) REFERENCES LOP(MALOP)
)
CREATE TABLE GIANGDAY
(
MALOP char(3) REFERENCES LOP(MALOP),
MAMH varchar(10) REFERENCES MONHOC(MAMH),
MAGV char(4) REFERENCES GIAOVIEN(MAGV),
HOCKY TINYINT,
NAM smallint,
TUNGAY smalldatetime,
DENNGAY smalldatetime
)
CREATE TABLE KETQUATHI
(
MAHV char(5) REFERENCES HOCVIEN(MAHV),
MAMH varchar(10) REFERENCES MONHOC(MAMH),
LANTHI TINYINT,
NGTHI smalldatetime,
DIEM numeric(4,2),
KQUA varchar(10)
)
ALTER TABLE KHOA ADD
CONSTRAINT KHOA_TRGKHOA_FK FOREIGN KEY (TRGKHOA) REFERENCES GIAOVIEN(MAGV)
ALTER TABLE LOP ADD
CONSTRAINT LOP_TRGLOP_FK FOREIGN KEY (TRGLOP) REFERENCES HOCVIEN(MAHV),
CONSTRAINT LOP_MAGVCN_FK FOREIGN KEY (MAGVCN) REFERENCES GIAOVIEN(MAGV)

You might also like