II.5.4. Modifying a Table

Now that you've seen how to get a full list of all your tables and see their data, it's time to check out how easy it is to change them. These types of alterations can include

  • Renaming the table

  • Renaming a column

  • Adding one or more columns to the table

  • Changing a data type for a given column

  • Changing a column's properties

  • Removing one or more columns from the table

  • Modifying properties for the table

We take a look at how to do each of these tasks. Because the SQL Server Management Studio is such an excellent tool, we use it as the primary mechanism to make these alterations. The initial steps that you need to follow for any modification are

  1. Launch the SQL Server Management Studio.

  2. Connect to the appropriate SQL Server instance.

  3. Expand the connection's entry in the Object Explorer view.

  4. Expand the Databases folder.

  5. Expand the specific database folder where your table resides.

  6. Locate the table you want to change.

II.5.4.1. Viewing a script for the table

Although the SQL Server Management Studio allows you to perform most administrative tasks without the need for programming, it's nice to know exactly what's going on underneath the covers. Here's how you can get a better understanding of the Data Definition Language (DDL) that SQL Server generates to build your table.

If you've followed the steps listed previously to locate the table, highlight the table name, right-click, and then choose Script Table ASCREATE TONew Query Window. You're presented with a script window, ...

Get Microsoft® SQL Server™ 2008 All-In-One Desk Reference For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.