DB2 alter table Field

Source: Internet
Author: User

DB2 alter: Add/delete/Reset Column

1. Add Fields

Alter table [table_name] add [column_name] [column_type]

2. Change the field type

Alter table [table_name] alter column [column_name] Set Data Type [column_type]

Note: There are restrictions on changing the field type. For example, you can change the field to be larger than the previous type length. to change it to a smaller value or modify the decimal point length, you must drop the original column first, and then add again.

For example, I want to change the column of A varchar (10) To varchar (6) or change the column of a decimal (16, 2) to decimal (16, 4, you cannot use the preceding statement to modify the column type. You must drop the column type first.

3. Remove Fields

Alter table [table_name] Drop column [column_name]

Note: After dropping a field, you may not be able to execute the Table query/insert operation. You Need To reorg the table.

4. Add default values for fields

Alter table [table_name] alter column [column_name] Set default [value]

5. Add fields with default values

Alter table [table_name] add column [column_name] [column_type] not null with default [value]

6. Set the default field time to the current time.

Alter table [table_name] alter column [column_name] Set default current date;

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.