Wednesday, July 23, 2014

How to quickly identify the change in the SQL Server

Recently i need to do an enhancement on the current existing application. My manager ask me to provide him a list of the change on the SQL Server in the staging environment.

It is very challenge to review every table, stored procedure and view to compare the change

here is a handy script to see the change of View in the last two week.

SELECT Name
FROM sys.objects
WHERE type = 'V'
AND DATEDIFF(D,Modify_Date, GETDATE()) < 14

To get the change of Stored Procedure

SELECT Name
FROM sys.objects
WHERE type = 'P'
AND DATEDIFF(D,Modify_Date, GETDATE()) < 14

To get change of User Table

SELECT Name
FROM sys.objects
WHERE type = 'U'
AND DATEDIFF(D,Modify_Date, GETDATE()) < 14


You can get the following types from MSDN

 sys.objects (Transact-SQL)

AF = Aggregate function (CLR)
C = CHECK constraint
D = DEFAULT (constraint or stand-alone)
F = FOREIGN KEY constraint
FN = SQL scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued function
IF = SQL inline table-valued function
IT = Internal table
P = SQL Stored Procedure
PC = Assembly (CLR) stored-procedure
PG = Plan guide
PK = PRIMARY KEY constraint
R = Rule (old-style, stand-alone)
RF = Replication-filter-procedure
S = System base table
SN = Synonym
SO = Sequence object
Applies to: SQL Server 2012 through SQL Server 2014.
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = SQL table-valued-function
TR = SQL DML trigger
TT = Table type
U = Table (user-defined)
UQ = UNIQUE constraint
V = View
X = Extended stored procedure

No comments:

Post a Comment