Use alter table in Oracle to add, delete, and modify the column syntax

Source: Internet
Author: User

Alter table tablename add (column datatype [default value] [null/not null],...);

Alter table tablename modify (column datatype [default value] [null/not null],...);

Alter table tablename drop (column );

Alter table is used to add, delete, and modify a column.

The following is an example:
Create table test1
(Id varchar2 (20) not null );

Alter table test1
Add (name varchar2 (30) default 'Anonymous 'not null );

Alter table test1
Modify (name varchar2 (16) default 'unknown ');

Alter table test1
Drop column name;

Create a table, add, change, and delete a column. Note that if a value already exists in a column, an error will occur if you want to modify the column width to be narrower than these values.

For example, if we insert a value
Insert into test1
Values ('1', 'We love you ');

Then I modified the column: alter table test1.
Modify (name varchar2 (8 ));
The following error is returned:
ERROR is located in row 2nd:
ORA-01441: cannot reduce column length because some values are too large

PS: Change the column name of an existing table

Alter table table_name rename column col_old to col_new

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.