復(fù)制代碼 代碼如下:
/******
對(duì)象: DdlTrigger [Trig_DBVersionController]
腳本日期: 09/05/2008 15:50:16
作用: 數(shù)據(jù)庫(kù)版本控制
******/
IF EXISTS (SELECT * FROM sys.triggers WHERE name = N'Trig_DBVersionController' AND parent_class=0)
DROP TRIGGER [Trig_DBVersionController] ON DATABASE
GO
CREATE TRIGGER [Trig_DBVersionController]
ON DATABASE
FOR CREATE_TABLE, ALTER_TABLE, DROP_TABLE,
CREATE_FUNCTION, ALTER_FUNCTION, DROP_FUNCTION,
CREATE_INDEX, ALTER_INDEX, DROP_INDEX,
CREATE_PROCEDURE, ALTER_PROCEDURE, DROP_PROCEDURE,
CREATE_TRIGGER, ALTER_TRIGGER, DROP_TRIGGER,
CREATE_VIEW, ALTER_VIEW, DROP_VIEW
AS
SET NOCOUNT ON
DECLARE @data AS xml
DECLARE @clientUser AS nvarchar(128)
DECLARE @spid AS nvarchar(128)
DECLARE @serverName AS nvarchar(128)
DECLARE @dbName AS nvarchar(128)
DECLARE @dbid AS int
DECLARE @objName AS nvarchar(512)
SELECT @data =EVENTDATA()
SELECT @spid = @data.value('(/EVENT_INSTANCE/SPID)[1]','nvarchar(128)')
SELECT @serverName = @data.value('(/EVENT_INSTANCE/ServerName)[1]','nvarchar(256)')
SELECT @dbName = @data.value('(/EVENT_INSTANCE/DatabaseName)[1]','nvarchar(128)')
SELECT @objName = @data.value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(128)')
SELECT @dbid = dbid FROM sys.sysdatabases
WHERE name = @dbName
--獲取客戶機(jī)的機(jī)器名
SELECT @clientUser=hostname FROM master..sysprocesses WHERE spid=@spid
-- add version record
INSERT INTO DBController.dbo.tbl_version_details
(post_computer_name, sys_dbid, uid, [schema],
PostTime, EventType, ObjectType, ObjectName, CommandText, Remark)
VALUES
(@clientUser, @dbid,
@data.value('(/EVENT_INSTANCE/LoginName)[1]','nvarchar(256)'),
@data.value('(/EVENT_INSTANCE/UserName)[1]','nvarchar(256)'),
@data.value('(/EVENT_INSTANCE/PostTime)[1]','datetime'),
@data.value('(/EVENT_INSTANCE/EventType)[1]','nvarchar(128)'),
@data.value('(/EVENT_INSTANCE/ObjectType)[1]','nvarchar(128)'),
@objName,
@data.value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','nvarchar(max)'),
''
)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ENABLE TRIGGER [Trig_DBVersionController] ON DATABASE
GO
上面是trigger
下面是存儲(chǔ)的庫(kù)和表結(jié)構(gòu)
提供圖片
上面圖片可以清淅看到表結(jié)構(gòu)
大家寫(xiě)出表的SQL出來(lái)
您可能感興趣的文章:- SQLServer 觸發(fā)器 數(shù)據(jù)庫(kù)進(jìn)行數(shù)據(jù)備份
- 數(shù)據(jù)庫(kù)觸發(fā)器(Trigger)的一點(diǎn)使用心得
- 用sql腳本創(chuàng)建sqlserver數(shù)據(jù)庫(kù)觸發(fā)器范例語(yǔ)句
- 數(shù)據(jù)庫(kù)觸發(fā)器DB2和SqlServer有哪些區(qū)別