简体   繁体   中英

How to generate multiple Alter Scripts in SSMS


I'm using sql server management studio 2008 to try and generate an alter script for each of my stored procedures in order to save the scripts for each revision. I can easily generate an alter script for each individual procedure, but I'm not trying to go through a hundred stored procedures manually.

I know that SSMS has an automated generate scripts function under task, but the only options are create, drop and create, and drop. I cant seem to figure out how to enable alter. I've already searched through many SO articles, as well as a little digging in msdn, and I've come up with nothing.

I'm hoping that the fine people of stackoverflow will be up to the challenge. Thanks in advance

It's not a very elegant solution but it would definitely work. Why not generate create script and then just replace all occurrences of CREATE PROCEDURE with ALTER PROCEDURE.

Use CHECK FOR OBJECT EXISTENCE option in Advanced Scripting Options. Script will contain set of IF NOT EXISTS... CREATE commands and below ALTER for each stored procedure you wanted to script.

You can generate stored procedures automatically from SQL SERVER Management Studio as following: 1) Right click on your database -> Tasks -> Generate Scripts 2) Select "specific database objects" then choose tables / stored procedures you want to generate script for them then press "Next" 3) In this window you can choose where you want to save your script, then you will find an option "Advanced", click it. Then you will find an option "Script DROP and Create",there are three options: Create, Drop, Drop and Create. Choose one as you want. 4) Then press ok, then "Next" and the script will be generated automatically.

If you want to change it from Create to Alter, just do "replace all" operation using any text editor. Hope this answer helps others.

Well, Drop/Create is the same as alter. By stating that you would like to use alter then you are certain that the target objects exists. Why not just select the group from the object explorer and right click select DROP/Create. This should do the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM