Professional Documents
Culture Documents
'Giant' 'Тип велосипеда %s'
'Giant' 'Тип велосипеда %s'
1)
create function task_function1(@velik nchar(20))
returns nchar(20)
as
begin
declare @type nchar(20)
select @type = T.Type
from Bicycle as B, TypesOfBicycle as T
where B.IdType = T.IdType and B.Name = @velik
return @type
end
2)
create function task_function2(@id_client int)
returns table
as
return
(
select B.Name as Bicycle, T.Type as [Type]
from Bicycle as B, TypesOfBicycle as T, [Rent date] as R
where B.IdType = T.IdType and R.BicycleId = B.IdBicycle and R.ClientId = @id_client
)
Триггеры
1)
create trigger check_date
on [Rent date]
for insert
as
begin
declare @dateto datetime
declare @datefrom datetime
select @dateto = [To], @datefrom = [From]
from inserted
2)
create trigger OnDelete on [Rent date]
for delete
as
declare @idrent int
declare @clientid int
declare @bicycleid int
declare @from date
declare @to date
declare @time smalldatetime = GETDATE()
select @idrent = deleted.IdRent, @clientid = deleted.ClientId, @bicycleid =
deleted.BicycleId, @from = deleted.[From], @to = deleted.[To]
from deleted
insert into TableOfChanging(IdRent, IdClient, IdBicycle, [From], [To], TimeOfAdding)
values(@idrent, @clientid, @bicycleid, @from, @to, @time)