# Miscellaneous > Database Design >  CHECK constraint - referencing another column

## Chris Williams

I receive the following error when creating a CHECK constraint that references another column. According to the good old Wrox SQL Server book, I&#39;m using the correct syntax. Anyone have any ideas???

Thanks in advance!

Server: Msg 8141, Level 16, State 1, Line 1
Column CHECK constraint for column &#39;end_date&#39; references another column, table &#39;Session&#39;.

Here&#39;s an example of the script that I&#39;m using:
CREATE TABLE Session (
session_key char(18) NOT NULL,
course_key char(18) NOT NULL,
site_key char(18) NOT NULL,
instructor_key char(18) NOT NULL,
start_date smalldatetime NULL,
end_date smalldatetime NULL
CHECK (end_date >= start_date)
)

----------


## ravish_eee

I think there is a problem in syntax, you have missed a coma at the end of "end_date smalldatetime NULL" give a coma there and run your command .i am sure it will work.......

----------


## skhanal

You replied to 8 years old thread.

----------


## vantung251

> I receive the following error when creating a CHECK constraint that references another column. According to the good old Wrox SQL Server book, I'm using the correct syntax. Anyone have any ideas???
> 
> Thanks in advance!
> 
> Server: Msg 8141, Level 16, State 1, Line 1
> Column CHECK constraint for column 'end_date' references another column, table 'Session'.
> 
> Here's an example of the script that I'm using:
> CREATE TABLE Session (
> ...


I think this code that is repaired :
There are 2 ways :
1. Make constraint "CHECK" in lavel table
CREATE TABLE Session (
session_key char(18) NOT NULL,
course_key char(18) NOT NULL,
site_key char(18) NOT NULL,
instructor_key char(18) NOT NULL,
start_date smalldatetime NULL,
end_date smalldatetime NULL,
CONSTRAINT date_ck CHECK (end_date >= start_date)
)

2. After create table Session
alter table Session
add constraint date_ck CHECK (end_date >= start_date)
)

Good day

----------


## vantung251

There are 2 ways for making constraint referencing another column.
1. Making constraint in table level :

CREATE TABLE Session (
session_key char(18) NOT NULL,
course_key char(18) NOT NULL,
site_key char(18) NOT NULL,
instructor_key char(18) NOT NULL,
start_date smalldatetime NULL,
end_date smalldatetime NULL,
CONSTRAINT date_ck CHECK (end_date >= start_date)
)

2. After creating table "Session"
alter table Session
add constraint date_chk CHECK (end_date >= start_date)

Funny with good day

----------

