创建表(MS Access 中的 SQL)

问题描述 投票:0回答:1

不运行,说约束子句中存在语法错误

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 syntax-error constraints
1个回答
0
投票

您的 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
选项。

© www.soinside.com 2019 - 2024. All rights reserved.