Code Project

Link Unit

Wednesday, August 24, 2005

Trigger

Hi All,
While inserting date value I wish to take only date part So I tried this
Create Table JTrial ( XYZ int, d datetime default convert(varchar,getdate(),112) )

insert into JTrial(XYZ) values(1)
insert into JTrial(XYZ) values(2)
insert into JTrial(XYZ) values(3)
insert into JTrial(XYZ) values(4)
select * from JTrial
Is there any better alternative.
Check constraint like this check ( d = convert(varchar,d,112) ) Will not allow me to insert row insert into JTrial(XYZ,d) values(5,getdate()) -- Because here date has time part
Is writing A trigger better alternative ?

Post a Comment