• Thank you for sharing.

    I am testing this on a SQL 2008 instance. I commented out the s.total_rows and s.last_rows columns in the spShowSlowQueries proc and it works fine after a little bit of troubleshooting.

    In case anyone else runs into an issue I am listing the steps to reproduce the problem, in SQL 2008, and the solution. I haven't traced the underlying issue though.

    Setup:

    1. Run the script as is

    2. Get Error

    Msg 207, Level 16, State 1, Procedure spShowSlowQueries, Line 25

    Invalid column name 'total_rows'.

    Msg 207, Level 16, State 1, Procedure spShowSlowQueries, Line 26

    Invalid column name 'last_rows'.

    3. Comment out the columns and run the script again.

    4. Get a bunch of creation failures due to the procs already existing but the spShowSlowQueries proc is created this time.

    Testing:

    1. Create Stored Proc

    CREATE PROCEDURE dbo.TestProc

    AS

    BEGIN

    SELECT 'TEST';

    END;

    2. Receive the following error.

    Msg 2801, Level 16, State 1, Procedure dtgLogSchemaChanges, Line 165

    The definition of object 'dtgLogSchemaChanges' has changed since it was compiled.

    The statement has been terminated."

    3. Try to create, drop, or alter any procs. Get same error.

    4. Try to drop the dtgLogSchemaChanges trigger from the database. Get same error.

    5. Try to run the spUninstall proc. Get same error.

    6. Disable the trigger.

    7. Test DDL statements. They should work now.

    8. Enable the trigger.

    8. Test DDL statements. They get errors again.

    Solution:

    1. Script the dtgLogSchemaChanges trigger out as a create to new window.

    2. Changed the create statement to an alter.

    3. Execute the statement.

    Test again:

    1. Create Stored Proc

    CREATE PROCEDURE dbo.TestProc

    AS

    BEGIN

    SELECT 'TEST';

    END;

    This should work now.

    I haven't traced out why the script puts it self in a bad state but if you get an error while running the script it is best to run the spUninstall proc to clear out everything and then start from scratch. The create script should be wrapped in a try catch to handle rollback on error.