Changing Table Definitions

After you've designed and created your database and worked with it for a while, you may find that it isn't quite right or that the application requirements have changed.

  • Most systems allow you to change the structure of a table (even after it has data in it) with the ALTER TABLE command. Syntax may include keywords to add and drop columns and to change a column's name, datatype, length, null status, and constraints.

  • You can also change table definitions by defining a view of the table or by creating a new table, loading the existing data into it, and then dropping the old. Some systems provide a single command that allows you to create and load a new table based on an old one.

Using ALTER TABLE

For example, to add a ...

Get Practical SQL Handbook, The: Using SQL Variants, Fourth Edition 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.