About Me

My photo
I am MCSE in Data Management and Analytics with specialization in MS SQL Server and MCP in Azure. I have over 13+ years of experience in IT industry with expertise in data management, Azure Cloud, Data-Canter Migration, Infrastructure Architecture planning and Virtualization and automation. Contact me if you are looking for any sort of guidance in getting your Infrastructure provisioning automated through Terraform. I sometime write for a place to store my own experiences for future search and read by own blog but can hopefully help others along the way. Thanks.

Script to get schema change history for specific day in SQL Server using server side trace


How to find schema change history  for specific day in SQL Server using server side trace

------------------------------------------------------------------------------------------


In order to get schema change history for specific date, Execute below query with specific .trc file.


By default .trc file resides in log folder of specific log folder of DB. 


SELECT * FROM:: fn_trace_gettable('E:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Log\log_XX.trc', default )

WHERE EventClass in (46,47,164) AND EventSubclass = 0 AND DatabaseID <> 2
and startTime >= '2017-02-15 00:00:00.980' and startTime <='2017-02-15 23:59:00.980'



For different event class refer below link


https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-trace-setevent-transact-sql?view=sql-server-2017


Here i have used event Classs

 46 --> 

46Object:CreatedIndicates that an object has been created, such as for CREATE INDEX, CREATE TABLE, and CREATE DATABASE statements.
 47 -->

47Object:DeletedIndicates that an object has been deleted, such as in DROP INDEX and DROP TABLE statements.

 164 -->
164Object:AlteredOccurs when a database object is altered.

Thanks for Reading