# How To Generate An Alter Table Script In SQL Easily!

**URL:** <https://onehack.st/t/how-to-generate-an-alter-table-script-in-sql-easily/62444>\
**Category:** Tutorials & Methods\
**Tags:** tools, programming, hacking, data-recovery\
**Created:** [November 20, 2019, 8:37pm UTC](https://onehack.st/t/how-to-generate-an-alter-table-script-in-sql-easily/62444 "2019-11-20T20:37:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aina](https://onehack.st/user_avatar/onehack.st/aina/32/167469_2.png) [@Aina](https://onehack.st/u/Aina)\
**Post date:** [November 20, 2019, 8:37pm UTC](https://onehack.st/t/how-to-generate-an-alter-table-script-in-sql-easily/62444/1 "2019-11-20T20:37:56Z")

</div>

In SQL 2005, you may come across a situation where you need to generate a ALTER TABLE script, such as when adding a new column to a database or changing the field type, etc.

If you want to generate a script for a particular SQL function, such as CREATE, SELECT, UPDATE, etc, you would normally just right-click on the table in SQL Management Studio and choose **Script Table as** and then the function you want to script.

 ![image](https://onehack.st/uploads/default/original/3X/0/a/0ac80109704abfed85e556efd6b4fadb826ee342.png)

However, the **ALTER To** option is disabled in the **Script Table as** menu option! So if you want to generate a script, how do you go about doing it? Well, you can’t do it this way when you alter a table.

In order to generate the script, you first right-click on the table you want to alter and choose **Design**.

 ![image](https://onehack.st/uploads/default/original/3X/5/8/58aed3c070e5084a94d45813acc9274fb307cc00.png)

Now go ahead and add your new columns, change the field types, set your fields to accept NULLS or not, etc. Once you are done, you want to right-click on any column or in the white space and you’ll see the option **Generate Change Script** is now available.

 ![image](https://onehack.st/uploads/default/original/3X/0/a/0abf750e13de9d78cfcd269a34a7bf79b0ec760d.png)

Now go ahead and save that file and you’ll have your ALTER TABLE script! It’s a bit confusing since all the other functions can be scripted just by right-clicking, but it’s simple once you learn it. Enjoy!

## ENJOY & HAPPY LEARNING! 👍
