我尝试使用以下代码在SQL Server中创建表:
CREATE TABLE LEARNERS
(
Id int NOT NULL Primary Key,
LastName varchar(255) NOT NULL,
FirstName varchar(255) NOT NULL,
Marital_Status char(1) DEFAULT 'S',
Address varchar(255),
Email varchar(255),
Parish varchar(50),
CONSTRAINT chk_LEARNERS CHECK (Id > 0
AND Parish in ('Kingston','St. Cathrine','Portland','St.Andrew'),
CONSTRAINT chk_Person_Marital CHECK (Marital_status = 'S' or Marital_Status = 'M'),
CONSTRAINT uk_email UNIQUE (Email),
)
但是有一条红线表示该行末尾的逗号正下方有错误
CONSTRAINT chk_LEARNERS CHECK (Id > 0 AND Parish IN ('Kingston','St. Cathrine','Portland','St.Andrew'),
出现的错误是:
''附近的语法错误不正确。期待')',AND或OR。
我似乎无法找到错误。可能是什么原因以及如何解决这个问题?
答案 0 :(得分:1)
检查约束中缺少close Parenthesis
CONSTRAINT chk_LEARNERS CHECK
(Id>0 AND Parish IN ('Kingston', 'St. Cathrine', 'Portland', 'St.Andrew')), --here
答案 1 :(得分:1)
您有两个错误:
closing parenthesis
CONSTRAINT chk_LEARNERS CHECK (Id>0 AND Parish in ('Kingston','St. Cathrine','Portland','St.Andrew'),
在关闭create table的括号之前comma
。