不运行,说约束子句中存在语法错误
CREATE TABLE Project
(
ProjectID INTEGER NOT NULL,
Name VARCHAR(25) NOT NULL,
DepartmentName VARCHAR(20) NOT NULL,
MaxHours NUMERIC NOT NULL,
StartDate DateTime,
EndDate DateTime,
CONSTRAINT PK_ProjectID PRIMARY KEY (ProjectID),
CONSTRAINT FK_DepartmentName
FOREIGN KEY (DepartmentName) REFERENCES Department (DepartmentName)
ON UPDATE CASCADE
ON DELETE NO ACTION
)
您的 SQL 语句存在问题:MS Access 不支持
ON UPDATE CASCADE
约束中的 ON DELETE NO ACTION
和 FOREIGN KEY
。
在 MS Access 中,您只能通过用户界面设置这些选项,而不能通过 SQL。
您可以创建不带这些选项的表,然后在 MS Access 用户界面中手动设置它们。创建表格的方法如下:
CREATE TABLE Project
(
ProjectID INTEGER NOT NULL,
Name VARCHAR(25) NOT NULL,
DepartmentName VARCHAR(20) NOT NULL,
MaxHours NUMERIC NOT NULL,
StartDate DateTime,
EndDate DateTime,
CONSTRAINT PK_ProjectID PRIMARY KEY (ProjectID),
CONSTRAINT FK_DepartmentName
FOREIGN KEY (DepartmentName) REFERENCES Department (DepartmentName)
)
然后,您可以在 MS Access 表关系用户界面中手动设置
CASCADE UPDATE
和 NO ACTION ON DELETE
选项。