<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Track Object &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/track-object/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Sun, 25 Sep 2016 19:49:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.5</generator>
	<item>
		<title>SQL Server: Encrypted DDL Trigger to Track all Database Changes</title>
		<link>https://www.dbrnd.com/2016/10/sql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security/</link>
					<comments>https://www.dbrnd.com/2016/10/sql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 21 Oct 2016 16:16:57 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[database security]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DDL Trigger]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[Track Object]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3674</guid>

					<description><![CDATA[I know, you guys are thinking that why we require DDL Trigger to track database changes in SQL Server. SQL Server already has Changed Data Capture (CDC) and Audit option. When we are talking about DDL Trigger, compare to other automated process this manual process is still preferred by SQL DBA because It is easy [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fsql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security%2F&amp;linkname=SQL%20Server%3A%20Encrypted%20DDL%20Trigger%20to%20Track%20all%20Database%20Changes" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fsql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security%2F&amp;linkname=SQL%20Server%3A%20Encrypted%20DDL%20Trigger%20to%20Track%20all%20Database%20Changes" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fsql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security%2F&amp;linkname=SQL%20Server%3A%20Encrypted%20DDL%20Trigger%20to%20Track%20all%20Database%20Changes" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fsql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security%2F&amp;linkname=SQL%20Server%3A%20Encrypted%20DDL%20Trigger%20to%20Track%20all%20Database%20Changes" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fsql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security%2F&amp;linkname=SQL%20Server%3A%20Encrypted%20DDL%20Trigger%20to%20Track%20all%20Database%20Changes" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fsql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security%2F&amp;linkname=SQL%20Server%3A%20Encrypted%20DDL%20Trigger%20to%20Track%20all%20Database%20Changes" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fsql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security%2F&#038;title=SQL%20Server%3A%20Encrypted%20DDL%20Trigger%20to%20Track%20all%20Database%20Changes" data-a2a-url="https://www.dbrnd.com/2016/10/sql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security/" data-a2a-title="SQL Server: Encrypted DDL Trigger to Track all Database Changes"></a></p><p>I know, you guys are thinking that why we require DDL Trigger to track database changes in SQL Server. </p>
<blockquote><p>SQL Server already has Changed Data Capture (CDC) and Audit option.<br />
When we are talking about DDL Trigger, compare to other automated process this manual process is still preferred by SQL DBA because It is easy to use and manage.</p></blockquote>
<blockquote><p>A Database Administrator is also responsible for all different types of Database Security like: Database / Schema / Object level permission, Tracking object creation. </p></blockquote>
<blockquote><p>I have enabled SQL Server Audit for one of our production report server, but some time It does not work as per the expectation.
</p></blockquote>
<blockquote><p>I have searched the alternate solution and found that we can create DDL trigger on a database to track the DDL operation of different objects.<br />
We can also use DDL triggers to verify the result of SQL Server Audit. </p></blockquote>
<p><strong>Other take care points of DDL Trigger are:</strong></p>
<blockquote><p>Only SA or Admin user has to perform this stuff. The DBA should restrict other common database user to view or modify the DDL trigger.</p></blockquote>
<blockquote><p>It should be encrypted. </p></blockquote>
<blockquote><p>If our database is heavily loaded with tons of transaction, we should not create any type of DDL trigger on it. </p></blockquote>
<p>Here, I am creating one encrypted DDL Trigger which tracks different types of object like:<br />
Stored Procedure, Table, View, Function, Trigger, Sequence, Index.</p>
<p><strong>Step to create Encrypted DDL Trigger:</strong></p>
<p><strong>First Create separate database:</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE [DDLChanges]
GO</pre> </p>
<p><strong>Create one table which will hold all event information:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE [DDLChanges].[dbo].[tbl_TrackDDLChanges](
	[EventDate] [datetime] NOT NULL DEFAULT (getdate()),
	[EventType] [nvarchar](64) NULL,
	[EventDDL] [nvarchar](max) NULL,
	[LoginName] [nvarchar](255) NULL,
	[DatabaseName] [nvarchar](255) NULL,
	[SchemaName] [nvarchar](255) NULL,
	[ObjectName] [nvarchar](255) NULL,
	[HostName] [varchar](64) NULL,
	[IPAddress] [varchar](32) NULL,
	[ProgramName] [nvarchar](255) NULL,
	[EventXML] [xml] NULL
)
GO</pre> </p>
<p><strong>SELECT your application Database and create below encrypted DDL trigger:</strong></p>
<blockquote><p>If you require to enable DDL trigger on multiple database, execute DDL trigger one by one on each require a database. </p></blockquote>
<blockquote><p>Please do not create a DDL Trigger on [DDLChanges] database, that we have created in the first step which is for tracking purposes.</p></blockquote>
<blockquote><p>Now, perform any DDL action on your database and check [DDLChanges].[dbo].[tbl_TrackDDLChanges] table where you can find important information like: which SQL Query, who created, which host, what time, on which database and other. </p></blockquote>
<pre class="crayon-plain-tag">CREATE TRIGGER [trg_DDL_Changes]
ON DATABASE
WITH ENCRYPTION
FOR 
	CREATE_PROCEDURE
	,ALTER_PROCEDURE
	,DROP_PROCEDURE
	,CREATE_TABLE
	,ALTER_TABLE
	,DROP_TABLE
	,CREATE_VIEW
	,ALTER_VIEW
	,DROP_VIEW
	,CREATE_FUNCTION
	,ALTER_FUNCTION
	,DROP_FUNCTION
	,CREATE_TRIGGER
	,ALTER_TRIGGER
	,DROP_TRIGGER
	,CREATE_SEQUENCE
	,ALTER_SEQUENCE
	,DROP_SEQUENCE
	,CREATE_INDEX
	,ALTER_INDEX
	,DROP_INDEX
AS
BEGIN
    SET NOCOUNT ON;
    DECLARE
        @EventData XML = EVENTDATA(); 
    DECLARE 
        @ip VARCHAR(32) =
        (
            SELECT client_net_address
            FROM sys.dm_exec_connections
            WHERE session_id = @@SPID
        );
 
    INSERT DDLChanges.dbo.tbl_TrackDDLChanges
    (
        EventType
        ,EventDDL
	,LoginName        
        ,DatabaseName
        ,SchemaName
        ,ObjectName
        ,HostName
        ,IPAddress
        ,ProgramName        
	,EventXML
    )
    SELECT
        @EventData.value('(/EVENT_INSTANCE/EventType)[1]','NVARCHAR(100)')
        ,@EventData.value('(/EVENT_INSTANCE/TSQLCommand)[1]','NVARCHAR(MAX)')
	,SUSER_SNAME()        
        ,DB_NAME()
        ,@EventData.value('(/EVENT_INSTANCE/SchemaName)[1]','NVARCHAR(255)')
        ,@EventData.value('(/EVENT_INSTANCE/ObjectName)[1]','NVARCHAR(255)')
        ,HOST_NAME()
        ,@ip
        ,PROGRAM_NAME()        
	,@EventData
END
GO</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/10/sql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
