database.sql 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. DROP TABLE student;
  2. DROP TABLE faculty;
  3. DROP TABLE class;
  4. DROP TABLE enrolled;
  5. --
  6. CREATE TABLE student
  7. (
  8. snum DECIMAL(9, 0) NOT NULL PRIMARY KEY,
  9. sname VARCHAR(30),
  10. major VARCHAR(25),
  11. standing VARCHAR(2),
  12. age DECIMAL(3, 0)
  13. );
  14. CREATE TABLE faculty
  15. (
  16. fid DECIMAL(9, 0) NOT NULL PRIMARY KEY,
  17. fname VARCHAR(30),
  18. deptid DECIMAL(2, 0)
  19. );
  20. CREATE TABLE class
  21. (
  22. name VARCHAR(40) NOT NULL PRIMARY KEY,
  23. meets_at VARCHAR(20),
  24. room VARCHAR(10),
  25. fid DECIMAL(9, 0),
  26. FOREIGN KEY(fid) REFERENCES faculty
  27. );
  28. CREATE TABLE enrolled
  29. (
  30. snum DECIMAL(9, 0) NOT NULL,
  31. cname VARCHAR(40) NOT NULL,
  32. PRIMARY KEY(snum, cname),
  33. FOREIGN KEY(snum) REFERENCES student,
  34. FOREIGN KEY(cname) REFERENCES class(name)
  35. );
  36. --
  37. import from student.txt of del insert into student;
  38. import from faculty.txt of del insert into faculty;
  39. import from class.txt of del insert into class;
  40. import from enrolled.txt of del insert into enrolled;