在Microsoft Access中创建表语法错误?

时间:2016-10-10 04:16:28

标签: sql ms-access

这是我的代码,我试图制作多个表格:

Create Table Order_t
(
Id AutoIncrement Not Null,
OrderDate DateTime Not Null,
CustId Int Not Null,
Primary Key(Id),
Foreign Key(CustId) References Customer_t(Id)
(;
Create Table PersonRole_t
(
PersonRoleID Autoincrement Not Null,
Person_ID int Not Null,
Primary Key(PersonRoleID, Person_ID),
Foreign Key(Person_ID) References Person_T(Person_ID)
(;
Create Table Product_t
(
Id Text(10) Not Null,
Name Text(30) Not Null,
Description Text(30),
Finish Text(30),
UnitPrice Currency Not Null,
Primary Key(Id)
) ;

每当我在Microsoft Access中运行它时,我在CREATE TABLE语句中出现错误(它突出显示PersonRole_T表定义)。不知道该怎么做,而不是SQL新手。

2 个答案:

答案 0 :(得分:1)

CLOSE表语句末尾使用CREATE 括号而不是OPEN 括号

Create Table Order_t
(
Id AutoIncrement Not Null,
OrderDate DateTime Not Null,
CustId Int Not Null,
Primary Key(Id),
Foreign Key(CustId) References Customer_t(Id)
); -- Not (;

Create Table PersonRole_t
(
PersonRoleID Autoincrement Not Null,
Person_ID int Not Null,
Primary Key(PersonRoleID, Person_ID),
Foreign Key(Person_ID) References Person_T(Person_ID)
); -- Not (; 

答案 1 :(得分:0)

Person_T语句可以执行之前,需要存在密钥为Person_ID的表References Person_T(Person_ID)。根据您的命名约定,我猜该语句应该是References Person_T(Id)

考虑更改命名约定,以便数据元素不会根据其对表/视图的实际位置更改其名称。还要考虑_t后缀是否值得打扰。

@ Prdp关于密切关注的观点也是有效的。