2009-07-01

Basic SQL: Alter (Part 7)

Alter statement is used to alter the structure of database objects, and like Create statement, different objects have different syntax. Below are example to alter a table:

  1. Add column:
    alter table [table name]
    add [column name] [data type]

    Example:
    alter table temp
    add test varchar(10);

  2. Remove column:
    alter table [table name]
    drop column [column name]

    Example:
    alter table temp
    drop column test;

  3. Add constraint:
    alter table [table name]
    add constraint [constraint name] [constraint type] [constraint details]

    Example:
    alter table temp
    add constraint temp_uk unique (name);

  4. Remove constraint:
    alter table [table name]
    drop constraint [constraint name]

    Example:
    alter table temp
    drop constraint temp_uk;

To change password of a user, use syntax below:
alter user [user name]
identified by [new password]

Example:
alter user james
identified by new_password;

0 comments: