[英]Access > SQL > Create Table . Constraints > Foreign Key
The below statement is being used to create a table CAMPUS.以下语句用于创建表 CAMPUS。 I am getting the Error:
我收到错误:
"Syntax error in CONSTRAINT clause"
“CONSTRAINT 子句中的语法错误”
"UPDATE" is highlighted signifying source of error.“更新”突出显示表示错误来源。
By removing "ON UPDATE CASCADE ON DELETE NO ACTION" I am able to create the table with no issues.通过删除“ON UPDATE CASCADE ON DELETE NO ACTION”,我可以毫无问题地创建表。
What is the proper syntax or procedure?正确的语法或程序是什么? (the MS Access "Help" was of no help)
(MS Access“帮助”没有帮助)
SQL Code: SQL 代码:
CREATE TABLE CAMPUS(
CampusID Counter(1,5) NOT NULL,
UnivID Long NOT NULL,
CampusName Text(50) NOT NULL,
Address Text(50) NULL,
Zip Number NULL,
Phone Number NULL,
CONSTRAINT CampusPK PRIMARY KEY (CampusID,UnivID),
CONSTRAINT CampusFK FOREIGN KEY (UnivID)
REFERENCES UNIVERSITY(UnivID)
ON UPDATE CASCADE
ON DELETE NO ACTION
CONSTRAINT CampusAK1 UNIQUE (CampusName)
);
Access (ACE, Jet, whatever) has supported referential actions in its SQL DLL since Jet 4.0 (Access2000).自 Jet 4.0 (Access2000) 以来,Access(ACE、Jet 等)在其SQL DLL中支持引用操作。 However, they are only available in ANSI-92 Query Mode .
但是,它们仅在ANSI-92 查询模式下可用。
With effect from Access2003, the Access UI can be placed in ANSI-92 Query Mode, allowing the newer, richer SQL DDL to be executed from the SQL View of a Query.从 Access2003 开始,Access UI 可以置于 ANSI-92 查询模式,允许从查询的 SQL 视图执行更新、更丰富的 SQL DDL。 Note that ADO (OLE DB) always uses ANSI-92 Query Mode and DAO uses "traditional" ANSI-89 Query Mode (however IIRC DAO's object model has been enhanced to include all referential actions including the post-89
SET NULL
action). Note that ADO (OLE DB) always uses ANSI-92 Query Mode and DAO uses "traditional" ANSI-89 Query Mode (however IIRC DAO's object model has been enhanced to include all referential actions including the post-89
SET NULL
action).
Therefore, I speculate that you are getting a syntax error because your are trying to execute ANSI-92 Query Mode SQL DDL while in ANSI-89 Query Mode.因此,我推测您遇到了语法错误,因为您在 ANSI-89 查询模式下尝试执行 ANSI-92 查询模式 SQL DDL。
It's been more then 10 years since I last used MS Access, but it seems you can only write either CASCADE
or SET NULL
after ON UPDATE
and ON DELETE
in a referential constraint.自从我上次使用 MS Access 以来已经 10 多年了,但似乎你只能在引用约束中的
ON UPDATE
和ON DELETE
之后编写CASCADE
或SET NULL
。
So basically you have to omit this part所以基本上你必须省略这部分
ON DELETE NO ACTION
Link http://www.sqlexamples.info/SQL/bsc_sqlddl1.htm链接http://www.sqlexamples.info/SQL/bsc_sqlddl1.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.