1. Computing

Discuss in my forum

Modifying Tables

Modifying Tables

By , About.com Guide

In the previous two sections of this article we explored the design of a database and the creation of tables to populate that database with information. In this final segment, we'll look at the mechanism SQL provides to alter the structure of a database after creation.

If you're particularly astute today, you might have noticed that we "accidentally" omitted one of the design requirements when implementing our database tables. XYZ Corporation's HR Director requested that the database track employee salary information and we neglected to provide for this in the database tables we created.

However, all is not lost. We can use the ALTER TABLE command to add this attribute to our existing database. We want to store the salary as an integer value. The syntax is quite similar to that of the CREATE TABLE command, here it is:
 ALTER TABLE employees
 ADD salary INTEGER NULL; 
Notice that we specified that NULL values are permitted for this attribute. In most cases there is no option when adding a column to an existing table. This is due to the fact that the table already contains rows with no entry for this attribute. Therefore, the DBMS automatically inserts a NULL value to fill the void.

And that wraps up our look at the SQL database and table creation process. Check back often for new installments in our SQL tutorial series. If you'd like an e-mail reminder when new articles are added to the About Databases site, be sure to subscribe to our newsletter!
  1. About.com
  2. Computing
  3. Databases
  4. Learning SQL
  5. Modifying Tables

©2013 About.com. All rights reserved.