Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I quickly identify most recently modified stored procedures in SQL Server

I Need to manually migrate modified stored procedures from a DEV SQL Server 2005 database instance to a TEST instance. Except for the changes I'm migrating, the databases have the same schemas. How can I quickly identify which stored procedures have been modified in the DEV database for migration to the TEST instance?

I assume I can write a query against some of the system tables to view database objects of type stored procedure, sorting by some sort of last modified or compiled data, but I'm not sure. Maybe there is some sort of free utility someone can point me to.

Thanks in advance,

Bob

like image 202
Bob OMalley Avatar asked Sep 17 '08 16:09

Bob OMalley


People also ask

How do I find the latest stored procedure in SQL Server?

Using SQL Server Management StudioExpand Databases, expand the database in which the procedure belongs, and then expand Programmability. Expand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To.

How do I find the last executed procedure in SQL Server?

The type_desc column includes the object type while the execution_count column shows the number of times the stored procedure has been executed since it was last compiled. This can be useful information when researching performance issues.


2 Answers

instead of using sysobjects which is not recommended anymore use sys.procedures

select name,create_date,modify_date from sys.procedures order by modify_date desc 

you can do the where clause yourself but this will list it in order of modification date descending

like image 142
SQLMenace Avatar answered Sep 20 '22 21:09

SQLMenace


Bob OMalley probably solved his problem long time ago but hopefully new readers will find this useful.

There are some special cases where scripts might not give optimal results.

One is deleting stored procedures or other objects in dev environment – you won’t catch this using system views because object won’t exist there any longer.

Also, I’m not really sure this approach can work on changes such as permissions and similar.

In such cases its best to use some third party tool just to double check nothing is missed.

I’ve successfully used ApexSQL Diff in the past for similar tasks and it worked really good on large databases with 1000+ objects but you can’t go wrong with SQL Compare that’s already mentioned here or basically any other tool that exists on the market.

Disclaimer: I’m not affiliated with any of the vendors I’m mentioning here but I do use both set of tools (Apex and RG) in the company I work for.

like image 34
Ron Biggs Avatar answered Sep 23 '22 21:09

Ron Biggs