Constant errors with check constraint in MS Access using SQL
ms-access, sql
Solution
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
Info: Constraints
Reserved words in Jet/Access pre 2007 and ACE/Access 2007-
Problem
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); ``` 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?