Skip to content

Instantly share code, notes, and snippets.

@dnthanh98
Last active November 23, 2018 15:19
Show Gist options
  • Save dnthanh98/ee87146ca8f060e1eb5b9c2da94a6a14 to your computer and use it in GitHub Desktop.
Save dnthanh98/ee87146ca8f060e1eb5b9c2da94a6a14 to your computer and use it in GitHub Desktop.
trigger_1660554
--2. Bình luận của một sản phẩm chỉ được đăng sau khi sản phẩm đó được đăng.
if OBJECT_ID('utr_cau2a', 'tr') is not null
drop trigger utr_cau2;
go
create trigger utr_cau2a on BINHLUAN
instead of insert
as begin
if exists (select * from inserted join SANPHAM on inserted.NgayDang < SANPHAM.NgayDang)
raiserror('Error', 16, 1);
else
insert into BINHLUAN select * from inserted;
return;
end
go
if OBJECT_ID('utr_cau2b', 'tr') is not null
drop trigger utr_cau2b;
go
create trigger utr_cau2b on SANPHAM
instead of insert
as begin
if exists (select * from inserted join BINHLUAN on inserted.NgayDang > BINHLUAN.NgayDang)
raiserror('Error', 16, 1);
else
insert into BINHLUAN select * from inserted;
return;
end
go
--6. Thời gian thao tác (trong lịch thao tác) trên sản phẩm phải sau thời gian đăng sản phẩm.
if OBJECT_ID('utr_cau3a', 'tr') is not null
drop trigger utr_cau3a;
go
create trigger utr_cau3a on LICHSUTHAOTAC
instead of insert
as begin
if exists(select * from inserted join SANPHAM on inserted.ThoiGian < SANPHAM.NgayDang)
raiserror('Error', 16, 1);
else
insert into LICHSUTHAOTAC select * from inserted;
return;
end
go
if OBJECT_ID('utr_cau3b', 'tr') is not null
drop trigger utr_cau3b;
go
create trigger utr_cau3b on SANPHAM
instead of insert
as begin
if exists(select * from inserted join LICHSUTHAOTAC on inserted.NgayDang > LICHSUTHAOTAC.ThoiGian)
raiserror('Error', 16, 1);
else
insert into SANPHAM select * from inserted;
return;
end
go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment