简体   繁体   English

操作数类型冲突:日期与 smallint 不兼容

[英]Operand type clash: date is incompatible with smallint

I want to create this table in SQL Server But it show date is incompatible with smallint error.我想在 SQL Server 中创建此表但它显示日期与 smallint 错误不兼容。

CREATE TABLE Trainees
(
    traineeID NCHAR(6) NOT NULL 
    CHECK  (traineeID LIKE '[0-9][0-9][0-9][0-9][0-9][0-9]') PRIMARY KEY,
    traineeName NVARCHAR (60) NOT NULL,
    traineeDOB DATE NOT NULL 
    CHECK (YEAR (traineeDOB) >=1991 AND NOT (traineeDOB) <=2002), 
    graduationYear DATE NOT NULL 
    CHECK (YEAR (graduationYear) >=2010 AND NOT (graduationYear) >=2021),
    Email NVARCHAR (50) NOT NULL UNIQUE,
    Phone NCHAR(11) NOT NULL 
    CHECK (traineeID LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),
    enrolledCourse INT REFERENCES Course (courseId) NOT NULL

)
GO

In your CHECK restrictions you are comparing a DATE with a smallint (traineeDOB) <=2002 and (graduationYear) >=2021 .在您的 CHECK 限制中,您将 DATE 与 smallint (traineeDOB) <=2002(graduationYear) >=2021 You should compare with a YEAR (smallint) with smallint, not DATE:您应该将 YEAR (smallint) 与 smallint 进行比较,而不是 DATE:

CREATE TABLE Trainees
(
    traineeID NCHAR(6) NOT NULL 
    CHECK  (traineeID LIKE '[0-9][0-9][0-9][0-9][0-9][0-9]') PRIMARY KEY,
    traineeName NVARCHAR (60) NOT NULL,
    traineeDOB DATE NOT NULL 
    CHECK (YEAR(traineeDOB) >=1991 AND NOT YEAR(traineeDOB) <=2002), 
    graduationYear DATE NOT NULL 
    CHECK (YEAR(graduationYear) >=2010 AND NOT YEAR(graduationYear) >=2021),
    Email NVARCHAR (50) NOT NULL UNIQUE,
    Phone NCHAR(11) NOT NULL 
    CHECK (traineeID LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),
    enrolledCourse INT REFERENCES Course (courseId) NOT NULL

)
GO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 操作数类型冲突:日期与sql server中的smallint错误不兼容 - Operand type clash: date is incompatible with smallint error in sql server EF核心更新数据库错误“操作数类型冲突:日期与smallint不兼容” - EF Core Update-Database error “Operand type clash: date is incompatible with smallint” 存储过程-操作数类型冲突:smallint与uniqueidentifier不兼容 - Stored procedure - Operand type clash: smallint is incompatible with uniqueidentifier 操作数类型冲突:日期与int不兼容? - Operand type clash: date is incompatible with int? SQL Server 2012(触发器)操作数类型冲突:int与日期不兼容 - SQL Server 2012 (triggers) Operand type clash: int is incompatible with date 存储过程操作数类型冲突:日期与int不兼容 - Stored Procedure Operand type clash: date is incompatible with int 操作数类型冲突:日期与用CONVERT()解决的int不兼容...为什么? - Operand type clash: date is incompatible with int solved with CONVERT() … but WHY? 如何解决操作数类型冲突:date is incompatible with int - How to resolve Operand type clash: date is incompatible with int 如何修复错误 - 操作数类型冲突:日期与 int 不兼容 - How to fix the error - Operand type clash: date is incompatible with int 操作数类型clash int与sql server中的日期不兼容 - operand type clash int is incompatible with date in sql server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM