为什么我的CREATE TABLES不能单独工作而不能一起工作?

时间:2019-02-19 17:56:08

标签: sql ms-access

我正在尝试在MS Access中运行包含多个CREATE TABLE语句的脚本。

当我尝试一起运行脚本时,在第二个CREATE TABLE上出现CREATE TABLE语法错误,但是当我通过SQL验证程序单独运行每个CREATE TABLE时,它们会通过成功。

通过将所有CREATE TABLE集中到一个脚本中,我在做什么错了?

CREATE TABLE MODEL (
  ModelNum INT NOT NULL,
  Capacity INT NOT NULL,
  MaxRange INT NOT NULL,
  CONSTRAINT ModelPK PRIMARY KEY(ModelNum)
);


CREATE TABLE AIRPLANE (
  RegNum INT NOT NULL,
  ModelNum INT NOT NULL,
  CONSTRAINT AirplanePK PRIMARY KEY(RegNum),
  CONSTRAINT AirplaneFK FOREIGN KEY(ModelNum) REFERENCES MODEL(ModelNum)
);


CREATE TABLE EMPLOYEE (
  SSN INT NOT NULL,
  EmpName VARCHAR(100) NOT NULL,
  Phone INT NULL,
  UnionMemberNum INT NULL,
  CONSTRAINT EmployeePK PRIMARY KEY(SSN)
);


CREATE TABLE TECHNICIAN (
  SSN INT NOT NULL,
  Salary INT NOT NULL,
  CONSTRAINT TechnicianPK PRIMARY KEY(SSN),
  CONSTRAINT TechnicianFK FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN)
);


CREATE TABLE TRAFFICCONTROLLER (
  SSN INT NOT NULL,
  DateOfTraining DATE NULL,
  CONSTRAINT TrafficControllerPK1 PRIMARY KEY(SSN),
  CONSTRAINT TrafficControllerFK1 FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN)
);


CREATE TABLE EXPERT(
  SSN INT NOT NULL,
  ModelNum INT NOT NULL,
  CONSTRAINT ExpertPK1 PRIMARY KEY(SSN),
  CONSTRAINT ExpertFK1 FOREIGN KEY(ModelNum) REFERENCES AIRPLANE(ModelNum)
);


CREATE TABLE TEST(
  Test_Num INT NOT NULL,
  TestName VARCHAR(100) NOT NULL,
  MaxScore INT NOT NULL,
  CONSTRAINT TestPK PRIMARY KEY(Test_Num)
);

CREATE TABLE TESTEVENTS(
  RegNum INT NOT NULL,
  Test_Num INT NOT NULL,
  SSN INT NOT NULL,
  TestDate DATE NOT NULL,
  Score INT NULL,
  CONSTRAINT TestEventsPK1 PRIMARY KEY(RegNum),
  CONSTRAINT TestEventsFK1 FOREIGN KEY(RegNum) REFERENCES AIRPLANE(RegNum),
  CONSTRAINT TestEventsPK2 PRIMARY KEY(Test_Num),
  CONSTRAINT TestEventsFK2 FOREIGN KEY(Test_Num) REFERENCES TEST(Test_Num),
  CONSTRAINT TestEventsPK3 PRIMARY KEY(SSN),
  CONSTRAINT TestEventsFK3 FOREIGN KEY(SSN) REFERENCES TECHNICIAN(SSN),
  CONSTRAINT TestEventsPK4 PRIMARY KEY(TestDate)
);

1 个答案:

答案 0 :(得分:0)

MS Access一次仅支持一个语句。