May 27th, 2009

Data Definition Language, ALTER TABLE

Posted by admin in Q. Data Definition Language

You use an ALTER TABLE comand to change names, data types, defaults, and constraints.Format:

  ALTER TABLE table_name
      {[ADD [COLUMN] column_name data_type [constraints]         Add a new column
     | [ALTER [COLUMN] column_name SET DEFAULT default_value]    Change a column default
     | [ALTER [COLUMN] column_name DROP DEFAULT]                 Remove a column default
     | [DROP [COLUMN] column_name [RESTRICT | CASCADE]]          Remove a column
     | [ADD CONSTRAINT table_constraint]                         Create a table constraint
     | [DROP CONSTRAINT constraint_name [RESTRICT | CASCADE]     Remove a table constraint
     | [RENAME TO new_table_name]};                              Rename a table

> You can create, change, or remove a table or column constraint, such as a primary key, foreign key, unique, or check constraint. ADD creates an entry, ALTER changes an entry, and DROP removes an entry.

> The format of the ALTER statement varies greatly from one RDBMS system to another. Consult your RDBMS documentation for the proper format and other parameters.

> DB2 will not allow you to DROP a column.

> DB2, MySQL, and Oracle don’t use ALTER, but use RENAME TABLE old_table_name TO new_table_name.

> PostgreSQL uses ALTER TABLE old_table_name TO new_table_name.

Comments are closed.

Sorry, the comment form is closed at this time.