Right click script alter table disabled in SQL Server Management Studio

Sql ServerSsmsAlter Table

Sql Server Problem Overview


I want to script a table as Alter to a New Query Editor Window. But this option is disabled. How can I do this?

Sql Server Solutions


Solution 1 - Sql Server

Use the "Design" function in SQL Server Management Studio to generate the ALTER script for you:

  • Right-click on the table you want to alter and choose Design.
  • Add new columns, change field types, set your fields to accept NULLS or not, etc.
  • Once you are done, click the Generate Change Script toolbar button (or right-click on any column or in the white space). This button looks like a floppy disk hovering over a piece of curled paper
  • Save the result to a text file

Depending on how you have your SSMS options set, this may not be available initially if the changes require tables to be dropped and re-created. To change this option, on the Tools menu, click Options, expand Designers, and then click Table and Database Designers. Select or clear the Prevent saving changes that require the table to be re-created check box.

Solution 2 - Sql Server

  1. Right-click on the table you want to alter and choose Design

  2. Add your new columns, change the field types, set your fields to accept NULLS or not, etc.

Important: Don't save your changes now

  1. Do a right-click on any column or in the white space and you’ll see the option Generate Change Script is now available.

Solution 3 - Sql Server

In SQL Server Management Studio 2016, toolbar button icon has changed. See the highlighted new icon.

New Icon for Generate Change Script

Solution 4 - Sql Server

  1. You can access this dialog box after you have made unsaved changes to a table in Table Designer. On the Table Designer menu, click Generate Change Script.

2.Automatically generate change script on every save If checked, the Save Change Script dialog box will appear any time you save changes to a table.

Yes Bring up the Save dialog box where you can choose the location for the text file.

No Cancel the creation of the change script.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHimanshu JansariView Question on Stackoverflow
Solution 1 - Sql Serverbhupendra patelView Answer on Stackoverflow
Solution 2 - Sql ServerVladLView Answer on Stackoverflow
Solution 3 - Sql ServerRavi SelvarajView Answer on Stackoverflow
Solution 4 - Sql ServerAmirhosseinView Answer on Stackoverflow