SQL Constraint: date A is before date B — How?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 01:07:08
create table foo
(
   from_date date,
   to_date date,
   constraint check_dates check (from_date < to_date)
);

Or if you need to apply this to an existing table, use:

alter table foo
   add constraint check_dates check (from_date < to_date);

The PostgreSQL manual contains a good chapter about check constraints: http://www.postgresql.org/docs/current/static/ddl-constraints.html#AEN2410

I think this is ok for sql server, mysql and oracle

ALTER TABLE myTbl
ADD CONSTRAINT chk_Dates CHECK (dtFrom < dtTo)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!