About Me

My photo
I am an MCSE in Data Management and Analytics, specializing in MS SQL Server, and an MCP in Azure. With over 19+ years of experience in the IT industry, I bring expertise in data management, Azure Cloud, Data Center Migration, Infrastructure Architecture planning, as well as Virtualization and automation. I have a deep passion for driving innovation through infrastructure automation, particularly using Terraform for efficient provisioning. If you're looking for guidance on automating your infrastructure or have questions about Azure, SQL Server, or cloud migration, feel free to reach out. I often write to capture my own experiences and insights for future reference, but I hope that sharing these experiences through my blog will help others on their journey as well. Thank you for reading!

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