Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right click script alter table disabled in SQL Server Management Studio

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

like image 254
Himanshu Jansari Avatar asked May 08 '12 12:05

Himanshu Jansari


2 Answers

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.

like image 147
bhupendra patel Avatar answered Sep 21 '22 06:09

bhupendra patel


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

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

like image 30
VladL Avatar answered Sep 22 '22 06:09

VladL