1. Log table
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HotelOrder_OrderStatus_Log]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HotelOrder_OrderStatus_Log](
[OrderStatusLogID] [int] IDENTITY(1,1) NOT NULL,
[AppName] [nvarchar](50) NOT NULL,
[EventInfo] [nvarchar](max) NOT NULL,
[SystemUser] [nvarchar](50) NOT NULL,
[HostName] [nvarchar](50) NOT NULL,
[TableName] [nvarchar](50) NOT NULL,
[RunTime] [datetime] NOT NULL
CONSTRAINT [PK__HotelOrder_OrderStatus_Log] PRIMARY KEY CLUSTERED
(
[OrderStatusLogID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
END
go
2. Trigger HotelOrder
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[CKHotelOrderupdateItem]'))
EXEC dbo.sp_executesql @statement = N'
CREATE trigger [dbo].[CKHotelOrderupdateItem] on [dbo].[HotelOrder]
for update
as
if update( OrderStatus ) and
( select top 1 createtime from inserted ) begin
set nocount on
declare @temp table ( EventType varchar(50), [Parameters] int ,EventInfo varchar(6000) )
declare @spid varchar(20)
set @spid = cast( @@spid as varchar )
insert @temp exec( ''DBCC INPUTBUFFER (''+ @spid +'')'' )
insert into [HotelOrder_OrderStatus_Log]
select App_Name(), EventInfo, SYSTEM_USER, Host_name(), ''HotelOrder'', getdate() from @temp
end'
go
3. Trigger HotelOrderDetail
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[CKHotelOrderDetailupdateItem]'))
EXEC dbo.sp_executesql @statement = N'
CREATE trigger [dbo].[CKHotelOrderDetailupdateItem] on [dbo].[HotelOrderDetail]
for update
as
if ( update( CheckInStatus ) or update( CheckOutStatus ) ) and
( select top 1 createtime from inserted ) begin
set nocount on
declare @temp table ( EventType varchar(50), [Parameters] int ,EventInfo varchar(6000) )
declare @spid varchar(20)
set @spid = cast( @@spid as varchar )
insert @temp exec( ''DBCC INPUTBUFFER (''+ @spid +'')'' )
insert into [HotelOrder_OrderStatus_Log]
select App_Name(), EventInfo, SYSTEM_USER, Host_name(), ''HotelOrderDetail'', getdate() from @temp
end'
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HotelOrder_OrderStatus_Log]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HotelOrder_OrderStatus_Log](
[OrderStatusLogID] [int] IDENTITY(1,1) NOT NULL,
[AppName] [nvarchar](50) NOT NULL,
[EventInfo] [nvarchar](max) NOT NULL,
[SystemUser] [nvarchar](50) NOT NULL,
[HostName] [nvarchar](50) NOT NULL,
[TableName] [nvarchar](50) NOT NULL,
[RunTime] [datetime] NOT NULL
CONSTRAINT [PK__HotelOrder_OrderStatus_Log] PRIMARY KEY CLUSTERED
(
[OrderStatusLogID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
END
go
2. Trigger HotelOrder
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[CKHotelOrderupdateItem]'))
EXEC dbo.sp_executesql @statement = N'
CREATE trigger [dbo].[CKHotelOrderupdateItem] on [dbo].[HotelOrder]
for update
as
if update( OrderStatus ) and
( select top 1 createtime from inserted ) begin
set nocount on
declare @temp table ( EventType varchar(50), [Parameters] int ,EventInfo varchar(6000) )
declare @spid varchar(20)
set @spid = cast( @@spid as varchar )
insert @temp exec( ''DBCC INPUTBUFFER (''+ @spid +'')'' )
insert into [HotelOrder_OrderStatus_Log]
select App_Name(), EventInfo, SYSTEM_USER, Host_name(), ''HotelOrder'', getdate() from @temp
end'
go
3. Trigger HotelOrderDetail
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[CKHotelOrderDetailupdateItem]'))
EXEC dbo.sp_executesql @statement = N'
CREATE trigger [dbo].[CKHotelOrderDetailupdateItem] on [dbo].[HotelOrderDetail]
for update
as
if ( update( CheckInStatus ) or update( CheckOutStatus ) ) and
( select top 1 createtime from inserted ) begin
set nocount on
declare @temp table ( EventType varchar(50), [Parameters] int ,EventInfo varchar(6000) )
declare @spid varchar(20)
set @spid = cast( @@spid as varchar )
insert @temp exec( ''DBCC INPUTBUFFER (''+ @spid +'')'' )
insert into [HotelOrder_OrderStatus_Log]
select App_Name(), EventInfo, SYSTEM_USER, Host_name(), ''HotelOrderDetail'', getdate() from @temp
end'