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

后端 未结 7 676
我寻月下人不归
我寻月下人不归 2021-01-31 04:03

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

相关标签:
7条回答
  • 2021-01-31 04:28

    you can also use the following code snipet

    USE AdventureWorks2008;
    
    GO
    
    SELECT SprocName=name, create_date, modify_date
    
    FROM sys.objects
    
    WHERE type = 'P' 
    
    AND name = 'uspUpdateEmployeeHireInfo'
    
    GO
    
    0 讨论(0)
  • 2021-01-31 04:30

    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

    0 讨论(0)
  • 2021-01-31 04:31

    There are several database compare tools out there. One that I've always like is SQLCompare by Red Gate.

    You can also try using:

    SELECT name
    FROM sys.objects
    WHERE modify_date > @cutoffdate
    

    In SQL 2000 that wouldn't have always worked, because using ALTER didn't update the date correctly, but in 2005 I believe that problem is fixed.

    I use a SQL compare tool myself though, so I can't vouch for that method 100%

    0 讨论(0)
  • 2021-01-31 04:33

    Although not free I have had good experience using Red-Gates SQL Compare tool. It worked for me in the past. They have a free trial available which may be good enough to solve your current issue.

    0 讨论(0)
  • 2021-01-31 04:36

    You can execute this query to find all stored procedures modified in the last x number of days:

    SELECT name
    FROM sys.objects
    WHERE type = 'P'
        AND DATEDIFF(D,modify_date, GETDATE()) < X
    
    0 讨论(0)
  • 2021-01-31 04:40

    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.

    0 讨论(0)
提交回复
热议问题