使用SQL的MS Access中带有检查约束的恒定错误 [英] Constant errors with check constraint in MS Access using SQL

查看:48
本文介绍了使用SQL的MS Access中带有检查约束的恒定错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此命令创建表:

I'm creating the table with this command:

CREATE TABLE Comp (
SerialNumber Number Primary Key Not Null,
Make Text(12) Not Null,
Model Text(24) Not Null,
ProcessorType Text(24) Null,
ProcessorSpeed Int Not Null,
MainMemory Text(15) Not Null,
DiskSize Text(15) Not Null
);

然后我尝试添加哪些约束:

Which works I then try to add the constraint:

ALTER TABLE Comp
ADD CONSTRAINT CheckSpeed
CHECK (ProcessorSpeed > 0);

哪个返回错误:"CONSTRAINT子句中的语法错误". 我尝试添加:

Which returns the error: "Syntax Error in CONSTRAINT Clause". I've tried adding:

CHECK (ProcessorSpeed > 0)

对于表创建命令,但它返回相同的错误.有什么办法解决这个问题?

To the table creation command but it returns the same error. Is there any way to solve this?

推荐答案

您需要针对连接运行,而Comp是保留字.

You need to run against a connection and Comp is a reserved word.

ss = "ALTER TABLE [Comp] ADD CONSTRAINT CheckSpeed CHECK (ProcessorSpeed > 0)"
CurrentProject.Connection.Execute ss

信息:约束

Jet/Access 2007年之前 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆