Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need help to create check constraint

Author  Topic 

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2012-01-23 : 22:18:58
My table design as following,
CREATE TABLE [dbo].[myGred](
[idx] [int] IDENTITY(1,1) NOT NULL,
[code] [varchar](50) NOT NULL,
[gred] [varchar](100) NOT NULL,
[stDte] [datetime] NOT NULL,
[edDte] [datetime] NOT NULL,
CONSTRAINT [PK_myGred] PRIMARY KEY CLUSTERED
(
[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [myGred_UQ1] UNIQUE NONCLUSTERED
(
[code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

stDte is a startDte. edDte is a endDte

My question as following,
1. How to create check constraint on stDte? The condition is stDte <= endDte

If possible, please guide me to create that check constraint

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2012-01-24 : 01:08:42
http://msdn.microsoft.com/en-us/library/ms188258.aspx

ALTER TABLE myGred
ADD CONSTRAINT chkDates CHECK (stDte <= endDte );
GO
Go to Top of Page

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2012-01-24 : 03:51:22
tq Mr LoztInSpace
Go to Top of Page
   

- Advertisement -