11 лаба от Вадима
This commit is contained in:
34
Lab11_Vadim/ex4.sql
Normal file
34
Lab11_Vadim/ex4.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
use AdventureWorks
|
||||
|
||||
--go
|
||||
|
||||
select * from Production.Product
|
||||
select * from Sales.SalesOrderDetail
|
||||
/*
|
||||
go
|
||||
create trigger OrderDetailNotDiscontinued
|
||||
on Sales.SalesOrderDetail
|
||||
instead of insert, update
|
||||
as
|
||||
begin
|
||||
declare @SelectProduct int
|
||||
if (exists (select * from deleted)) -- <20><><EFBFBD><EFBFBD> deleted <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD> update)
|
||||
set @SelectProduct = (select ProductID from deleted)
|
||||
else
|
||||
set @SelectProduct = (select ProductID from inserted)
|
||||
|
||||
if (exists (select * from Production.Product where ProductID = @SelectProduct and DiscontinuedDate is not null))
|
||||
Raiserror('Error',16,1)
|
||||
end
|
||||
*/
|
||||
go
|
||||
select ProductID, Name
|
||||
from Production.Product
|
||||
where DiscontinuedDate is not null
|
||||
|
||||
update Production.Product
|
||||
set DiscontinuedDate = GETDATE()
|
||||
where ProductID = 680
|
||||
|
||||
insert Sales.SalesOrderDetail (SalesOrderID, OrderQty, ProductID, SpecialOfferID, UnitPrice, UnitPriceDiscount)
|
||||
values(43660, 5,680,1,1431,0)
|
||||
Reference in New Issue
Block a user