Advertisement
Reading_Steiner

Untitled

Apr 17th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.50 KB | None | 0 0
  1.  
  2. CREATE TABLE TRUONGDH(
  3. MATRUONG CHAR(6) NOT NULL PRIMARY KEY, CHECK (MATRUONG LIKE 'DH[0-9][0-9][0-9][0-9]'),
  4. TENTRUONG NVARCHAR2(30) NOT NULL UNIQUE,
  5. DIACHI NVARCHAR2(30),
  6. MUCTIEU NVARCHAR2(30)
  7. );
  8.  
  9. CREATE TABLE NGANH(
  10. MANGANH CHAR(5) NOT NULL, CHECK (MANGANH LIKE 'NG[0-9][0-9][0-9]'),
  11. MATRUONG CHAR(6) NOT NULL,
  12. TENNGANH NVARCHAR2(30) NOT NULL,
  13. THONGTINDAURA clob,
  14. DECUONGDAOTAO clob,
  15. CONSTRAINT NGANH_PK PRIMARY KEY (MANGANH, MATRUONG) ENABLE
  16. );
  17.  
  18. ALTER TABLE NGANH ADD CONSTRAINT FG_NGANH_MATRUONG FOREIGN KEY (MATRUONG) REFERENCES TRUONGDH(MATRUONG)
  19.  
  20. CREATE TABLE KHOI(
  21. TENKHOI CHAR(3) NOT NULL PRIMARY KEY, CHECK (TENKHOI LIKE '[A-Z][0-9][0-9]')
  22. );
  23.  
  24. CREATE TABLE THONGTINTUYENSINH(
  25. MATRUONG CHAR(6) NOT NULL,
  26. MANGANH CHAR(5) NOT NULL,
  27. TENKHOI CHAR(3) NOT NULL,
  28. TYLECHOI NUMBER(*, 2),
  29. CHITIEU INT, CHECK (CHITIEU>0),
  30. DIEMCHUANNAMNGOAI NUMBER(*, 2), CHECK (DIEMCHUANNAMNGOAI>0),
  31. DIEMCHUANNV1 NUMBER(*,2), CHECK (DIEMCHUANNV1>0),
  32. DIEMCHUANNV2 NUMBER(*,2), CHECK (DIEMCHUANNV2>0),
  33. DIEMCHUANNV3 NUMBER(*,2), CHECK (DIEMCHUANNV3>0),
  34. CONSTRAINT THONGTINTUYENSINH_PK PRIMARY KEY (MATRUONG, MANGANH, TENKHOI) ENABLE
  35. );
  36.  
  37. ALTER TABLE THONGTINTUYENSINH ADD CONSTRAINT FG_TTTS_MATRUONG_MANGANH FOREIGN KEY (MATRUONG, MANGANH) REFERENCES NGANH(MATRUONG, MANGANH)
  38. ALTER TABLE THONGTINTUYENSINH ADD CONSTRAINT FG_TTTS_TENKHOI FOREIGN KEY (TENKHOI) REFERENCES KHOI(TENKHOI)
  39.  
  40. CREATE TABLE MONTHI(
  41. TENKHOI CHAR(3) NOT NULL,
  42. STT CHAR(4) NOT NULL, CHECK (STT LIKE 'MT[0-9][0-9]'),
  43. TENMON NVARCHAR2(20) NOT NULL,
  44. THOIGIANTHI INT, CHECK (THOIGIANTHI<=180),
  45. GIOBATDAU CHAR(5), CHECK (GIOBATDAU LIKE '[0-9][0-9]:[0-9][0-9]'),
  46. MABUOITHI CHAR(3),
  47. CONSTRAINT MONTHI_PK PRIMARY KEY (TENKHOI, STT) ENABLE
  48. );
  49.  
  50. ALTER TABLE MONTHI ADD CONSTRAINT FG_MONTHI_TENKHOI FOREIGN KEY (TENKHOI) REFERENCES KHOI(TENKHOI)
  51.  
  52. CREATE TABLE BUOITHI(
  53. MABUOITHI CHAR(3) NOT NULL PRIMARY KEY,
  54. NGAY DATE,
  55. SANGHAYCHIEU INT, CHECK (SANGHAYCHIEU BETWEEN 0 AND 1)
  56. );
  57.  
  58. ALTER TABLE MONTHI ADD CONSTRAINT FG_MONTHI_MABUOITHI FOREIGN KEY (MABUOITHI) REFERENCES BUOITHI(MABUOITHI)
  59.  
  60. CREATE TABLE TRUONGTHPT(
  61. MATRUONGTHPT CHAR(8) NOT NULL PRIMARY KEY, CHECK (MATRUONGTHPT LIKE 'THPT[0-9][0-9][0-9][0-9]'),
  62. TENTRUONGTHPT NVARCHAR2(40) NOT NULL
  63. );
  64.  
  65. CREATE TABLE NHANSU(
  66. ID CHAR(7) NOT NULL PRIMARY KEY, CHECK (ID LIKE '[TS|GT|TT|CB][0-9][0-9][0-9][0-9][0-9]'),
  67. CMND CHAR (10) NOT NULL UNIQUE,
  68. HOTEN NVARCHAR2(50)
  69. );
  70.  
  71. CREATE TABLE THISINH(
  72. ID CHAR(7) NOT NULL PRIMARY KEY, CHECK (ID LIKE 'TS[0-9][0-9][0-9][0-9][0-9]'),
  73. DIACHI NVARCHAR2(30),
  74. QUEQUAN NVARCHAR2(20),
  75. DIENTHOAI CHAR(10),
  76. MATRUONGTHPT CHAR(8)
  77. );
  78.  
  79. ALTER TABLE THISINH ADD CONSTRAINT FG_THISINH_ID FOREIGN KEY (ID) REFERENCES NHANSU(ID)
  80. ALTER TABLE THISINH ADD CONSTRAINT FG_THISINH_MATRUONGTHPT FOREIGN KEY (MATRUONGTHPT) REFERENCES TRUONGTHPT(MATRUONGTHPT)
  81.  
  82. CREATE TABLE CANBO(
  83. ID CHAR(7) NOT NULL PRIMARY KEY,
  84. CONGVIEC NVARCHAR2(20),
  85. CHECK ((CONGVIEC = 'GIAM THI' AND ID LIKE 'GT[0-9][0-9][0-9][0-9][0-9]') OR (CONGVIEC = 'TRAT TU VIEN' AND ID LIKE 'TT[0-9][0-9][0-9][0-9][0-9]') OR (CONGVIEC <> 'GIAM THI' AND CONGVIEC <> 'TRAT TU VIEN' AND ID LIKE 'CB[0-9][0-9][0-9][0-9][0-9]'))
  86. );
  87.  
  88. ALTER TABLE CANBO ADD CONSTRAINT FG_CANBO_ID FOREIGN KEY (ID) REFERENCES NHANSU(ID)
  89.  
  90. CREATE TABLE HOSOTHISINHTHI(
  91. ID CHAR(7) NOT NULL,
  92. MATRUONG CHAR(6) NOT NULL,
  93. MANGANH CHAR(5) NOT NULL,
  94. TENKHOI CHAR(3) NOT NULL,
  95. SBD CHAR(5) NOT NULL, CHECK (SBD LIKE '[0-9][0-9][0-9][0-9][0-9]'),
  96. MADIADIEM CHAR(5),
  97. SOPHONG INT,
  98. TONGDIEM NUMBER(*,2) DEFAULT -1.00,
  99. CONSTRAINT HOSOTHISINHTHI_PK PRIMARY KEY (ID, MATRUONG, MANGANH, TENKHOI, SBD) ENABLE
  100. );
  101.  
  102. ALTER TABLE HOSOTHISINHTHI ADD CONSTRAINT FG_HSTST_ID FOREIGN KEY (ID) REFERENCES THISINH(ID)
  103. ALTER TABLE HOSOTHISINHTHI ADD CONSTRAINT FG_HSTST_MATRUONG_MANGANH FOREIGN KEY (MATRUONG, MANGANH) REFERENCES NGANH(MATRUONG, MANGANH)
  104. ALTER TABLE HOSOTHISINHTHI ADD CONSTRAINT FG_HSTST_TENKHOI FOREIGN KEY (TENKHOI) REFERENCES KHOI(TENKHOI)
  105.  
  106. CREATE TABLE THISINHDANGKYNGUYENVONG(
  107. ID CHAR(7) NOT NULL,
  108. MATRUONG CHAR(6) NOT NULL,
  109. MANGANH CHAR(5) NOT NULL,
  110. TENKHOI CHAR(3) NOT NULL,
  111. SBD CHAR(5) NOT NULL,
  112. MATRUONG2 CHAR(6) NOT NULL,
  113. MANGANH2 CHAR(5) NOT NULL,
  114. NV2HAYNV3 INT NOT NULL, CHECK (NV2HAYNV3 BETWEEN 1 AND 2),
  115. CONSTRAINT THISINHDANGKYNGUYENVONG_PK PRIMARY KEY (ID, MATRUONG, MANGANH, TENKHOI, SBD, MATRUONG2, MANGANH2) ENABLE
  116. );
  117.  
  118. ALTER TABLE THISINHDANGKYNGUYENVONG ADD CONSTRAINT FG_TSDKNV_THONGTIN FOREIGN KEY (ID, MATRUONG, MANGANH, TENKHOI, SBD) REFERENCES HOSOTHISINHTHI(ID, MATRUONG, MANGANH, TENKHOI, SBD)
  119. ALTER TABLE THISINHDANGKYNGUYENVONG ADD CONSTRAINT FG_TSDKNV_MATRUONG2_MANGANH2 FOREIGN KEY (MATRUONG2, MANGANH2) REFERENCES NGANH(MATRUONG, MANGANH)
  120.  
  121. CREATE TABLE DIADIEMTHI(
  122. MADIADIEM CHAR(5) NOT NULL PRIMARY KEY, CHECK (MADIADIEM LIKE 'DD[0-9][0-9][0-9]'),
  123. TENDIADIEM NVARCHAR2(30),
  124. DIACHI NVARCHAR2(30)
  125. );
  126.  
  127. CREATE TABLE PHONGTHI(
  128. MADIADIEM CHAR(5) NOT NULL,
  129. SOPHONG INT NOT NULL,
  130. TONGSOTHISINH INT,
  131. MAHANHLANG CHAR(6),
  132. CONSTRAINT PHONGTHI_PK PRIMARY KEY (MADIADIEM, SOPHONG) ENABLE
  133. );
  134.  
  135. ALTER TABLE HOSOTHISINHTHI ADD CONSTRAINT FG_HSTST_MADIADIEM_SOPHONG FOREIGN KEY (MADIADIEM, SOPHONG) REFERENCES PHONGTHI(MADIADIEM, SOPHONG)
  136. ALTER TABLE PHONGTHI ADD CONSTRAINT FG_PHONGTHI_MADIADIEM FOREIGN KEY (MADIADIEM) REFERENCES DIADIEMTHI(MADIADIEM)
  137.  
  138. CREATE TABLE THISINHVANG(
  139. ID CHAR(7) NOT NULL,
  140. MATRUONG CHAR(6) NOT NULL,
  141. MANGANH CHAR(5) NOT NULL,
  142. TENKHOI CHAR(3) NOT NULL,
  143. SBD CHAR(5) NOT NULL,
  144. MABUOITHI CHAR(3) NOT NULL,
  145. CONSTRAINT THISINHVANG_PK PRIMARY KEY (ID, MATRUONG, MANGANH, TENKHOI, SBD, MABUOITHI) ENABLE
  146. );
  147.  
  148. ALTER TABLE THISINHVANG ADD CONSTRAINT FG_TSV_THONGTIN FOREIGN KEY (ID, MATRUONG, MANGANH, TENKHOI, SBD) REFERENCES HOSOTHISINHTHI(ID, MATRUONG, MANGANH, TENKHOI, SBD)
  149. ALTER TABLE THISINHVANG ADD CONSTRAINT FG_TSV_MABUOITHI FOREIGN KEY (MABUOITHI) REFERENCES BUOITHI(MABUOITHI)
  150.  
  151. CREATE TABLE SOTHISINHCOMATTRONGPHONGTHI(
  152. MADIADIEM CHAR(5) NOT NULL,
  153. SOPHONG INT NOT NULL,
  154. MABUOITHI CHAR(3) NOT NULL,
  155. SOTHISINHCOMAT INT default -1,
  156. CONSTRAINT SOTHISINHCOMATTRONGPHONGTHI_PK PRIMARY KEY (MADIADIEM, SOPHONG, MABUOITHI) ENABLE
  157. );
  158.  
  159. ALTER TABLE SOTHISINHCOMATTRONGPHONGTHI ADD CONSTRAINT FG_STSCMTPT_MADIADIEM_SOPHONG FOREIGN KEY (MADIADIEM, SOPHONG) REFERENCES PHONGTHI(MADIADIEM, SOPHONG)
  160. ALTER TABLE SOTHISINHCOMATTRONGPHONGTHI ADD CONSTRAINT FG_STSCMTPT_MABUOITHI FOREIGN KEY (MABUOITHI) REFERENCES BUOITHI(MABUOITHI)
  161.  
  162. CREATE TABLE HANHLANG(
  163. MAHANHLANG CHAR(6) NOT NULL PRIMARY KEY, CHECK (MAHANHLANG LIKE 'HL[0-9][0-9][0-9][0-9]')
  164. );
  165.  
  166. ALTER TABLE PHONGTHI ADD CONSTRAINT FG_PHONGTHI_MAHANHLANG FOREIGN KEY (MAHANHLANG) REFERENCES HANHLANG(MAHANHLANG)
  167.  
  168. CREATE TABLE GIAMTHIGACTHI(
  169. MAGT1 CHAR(7),
  170. MAGT2 CHAR(7),
  171. MABUOITHI CHAR(3) NOT NULL,
  172. MADIADIEM CHAR(5) NOT NULL,
  173. SOPHONG INT NOT NULL,
  174. CONSTRAINT GIAMTHIGACTHI_PK PRIMARY KEY (MABUOITHI, MADIADIEM, SOPHONG) ENABLE
  175. );
  176.  
  177. ALTER TABLE GIAMTHIGACTHI ADD CONSTRAINT FG_GTGT_MAGT1 FOREIGN KEY (MAGT1) REFERENCES CANBO(ID) ADD CONSTRAINT GT1_CK CHECK (MAGT1 LIKE 'GT[0-9][0-9][0-9][0-9][0-9]')
  178. ALTER TABLE GIAMTHIGACTHI ADD CONSTRAINT FG_GTGT_MAGT2 FOREIGN KEY (MAGT2) REFERENCES CANBO(ID) ADD CONSTRAINT GT2_CK CHECK (MAGT2 LIKE 'GT[0-9][0-9][0-9][0-9][0-9]') ADD CONSTRAINT CK_GT2 CHECK (MAGT2 <> MAGT1)
  179. ALTER TABLE GIAMTHIGACTHI ADD CONSTRAINT FG_GTGT_MABUOITHI FOREIGN KEY (MABUOITHI) REFERENCES BUOITHI(MABUOITHI)
  180. ALTER TABLE GIAMTHIGACTHI ADD CONSTRAINT FG_GTGT_MADIADIEM_SOPHONG FOREIGN KEY (MADIADIEM, SOPHONG) REFERENCES PHONGTHI(MADIADIEM, SOPHONG)
  181.  
  182. CREATE TABLE TRATTUVIENGIAMSAT(
  183. MABUOITHI CHAR(3) NOT NULL,
  184. MAHANHLANG CHAR(6) NOT NULL,
  185. MATTV1 CHAR(7),
  186. MATTV2 CHAR(7),
  187. CONSTRAINT TRATTUVIENGIAMSAT_PK PRIMARY KEY (MABUOITHI, MAHANHLANG) ENABLE
  188. );
  189.  
  190. ALTER TABLE TRATTUVIENGIAMSAT ADD CONSTRAINT FG_TTVGS_MABUOITHI FOREIGN KEY (MABUOITHI) REFERENCES BUOITHI(MABUOITHI)
  191. ALTER TABLE TRATTUVIENGIAMSAT ADD CONSTRAINT FG_TTVGS_MATTV1 FOREIGN KEY (MATTV1) REFERENCES CANBO(ID) ADD CONSTRAINT TTV1_CK CHECK (MATTV1 LIKE 'TT[0-9][0-9][0-9][0-9][0-9]')
  192. ALTER TABLE TRATTUVIENGIAMSAT ADD CONSTRAINT FG_TTVGS_MATTV2 FOREIGN KEY (MATTV2) REFERENCES CANBO(ID) ADD CONSTRAINT TTV2_CK CHECK (MATTV2 LIKE 'TT[0-9][0-9][0-9][0-9][0-9]') ADD CONSTRAINT CK_TTV2 CHECK (MATTV2 <> MATTV1)
  193. ALTER TABLE TRATTUVIENGIAMSAT ADD CONSTRAINT FG_TTVGS_MAHANHLANG FOREIGN KEY (MAHANHLANG) REFERENCES HANHLANG(MAHANHLANG)
  194.  
  195. CREATE TABLE QUYCHE(
  196. MAQUYCHE CHAR(5) NOT NULL PRIMARY KEY, CHECK (MAQUYCHE LIKE 'QC[0-9][0-9][0-9]'),
  197. MOTA NVARCHAR2(40),
  198. XULY NVARCHAR2(40)
  199. );
  200.  
  201. CREATE TABLE VIPHAMQUYCHE(
  202. ID CHAR(7)NOT NULL,
  203. MAQUYCHE CHAR(5) NOT NULL,
  204. MABUOITHI CHAR(3) NOT NULL,
  205. CONSTRAINT VIPHAMQUYCHE_PK PRIMARY KEY(ID, MAQUYCHE, MABUOITHI)ENABLE
  206. );
  207.  
  208. ALTER TABLE VIPHAMQUYCHE ADD CONSTRAINT FG_VPQC_ID FOREIGN KEY (ID) REFERENCES NHANSU(ID)
  209. ALTER TABLE VIPHAMQUYCHE ADD CONSTRAINT FG_VPQC_MAQUYCHE FOREIGN KEY (MAQUYCHE) REFERENCES QUYCHE(MAQUYCHE)
  210. ALTER TABLE VIPHAMQUYCHE ADD CONSTRAINT FG_VPQC_MABUOITHI FOREIGN KEY (MABUOITHI) REFERENCES BUOITHI(MABUOITHI)
  211.  
  212. CREATE TABLE KETQUATHI(
  213. ID CHAR(7) NOT NULL,
  214. MATRUONG CHAR(6) NOT NULL,
  215. MANGANH CHAR(5) NOT NULL,
  216. TENKHOI CHAR(3) NOT NULL,
  217. SBD CHAR(5) NOT NULL,
  218. STT CHAR(4) NOT NULL,
  219. DIEMTHI NUMBER(*,2), CHECK (DIEMTHI < 10.00),
  220. DIEMPHUCTRA NUMBER(*,2) DEFAULT -1.00, CHECK (DIEMPHUCTRA < 10.00),
  221. CONSTRAINT KETQUATHI_PK PRIMARY KEY (ID, MATRUONG, MANGANH, TENKHOI, SBD, STT) ENABLE
  222. );
  223.  
  224. ALTER TABLE KETQUATHI ADD CONSTRAINT FG_KQT_THONGTIN FOREIGN KEY (ID, MATRUONG, MANGANH, TENKHOI, SBD) REFERENCES HOSOTHISINHTHI(ID, MATRUONG, MANGANH, TENKHOI, SBD)
  225. ALTER TABLE KETQUATHI ADD CONSTRAINT FG_KQT_TENKHOI_STT FOREIGN KEY (TENKHOI, STT) REFERENCES MONTHI(TENKHOI, STT)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement