Monday, June 20, 2022

Buggish: MS SQL SMO StoredProcedure ScriptHeader(false) with renamed stored procedure

The SMO StoredProcedure ScriptHeader(false) will return the original stored procedure name (ie this is the script originally used to create the stored procedure). Because it has been renamed, this is no longer the value that I want. I want a create script with the new name.

According to this post: https://social.msdn.microsoft.com/Forums/silverlight/en-US/6de78652-3780-403b-893f-da4ef8a01ed8/textheader?forum=sqlsmoanddmo

This is a known issue. It also references:

https://www.sqlservercentral.com/articles/ssis-%e2%80%93-transfer-sql-server-objects-debugged

https://www.sqlservercentral.com/forums/topic/ssis-%e2%80%93-transfer-sql-server-objects-debugged


My resolution is to use the ScriptHeader(true) and change ALTER PROCEDURE to CREATE PROCEDURE as it is easier than parsing or replacing the stored procedure name. I also need to use ScriptHeader to preserve the documentation in the header.

I also use this to move db objects from one server to another.


NOTE: I think this only happens if a rename is used. To workaround this before, I would just run the alter script on itself. I wanted to get away from that because it would change the last updated datetime which I also used as part of my fuzzy logic in determining script versions that are not source controlled.

No comments:

Post a Comment