Dataintegrity between tables in SQL Server -
is possible add data integrity between columns in different tables in sql server? have table pay column date , table orders column dateoforder. , add data integrity date cannot earlier dateoforder. , when user insert there same date or earlier database show error.
i think mean this, here done trigger;
create trigger trig_pay on pay insert, update if exists(select * [order] o join inserted on o.id = i.payment_id dateoforder>[date]) begin raiserror ('sorry, dave', 16, 1) rollback; return; end insert [order] values (1, getdate()); -- order today insert pay values (1, dateadd(dd, -1, getdate())); -- pay yesterday > sorry, dave
Comments
Post a Comment