Db2-alter Append/delete/Reset column operations

Source: Internet
Author: User
Tags db2

DB2-alter Append/delete/reset column operation  1. add field  alter table name add field Name Type  demo:1alter Table table_name  add   Column_test VARCHAR (50); 2. Change field type  alter table name alter COLUMN field name set data type type  DEMO: 1ALTER TABLE table_name ALTER COLUMN COLUMN_ Test Set Data type VARCHAR (3);  Note: There is an operational limit to changing the field type. To change the field to be larger than the previous type, if you want to make it smaller, you must first drop the original column and then add it again. For example, I want to change a varchar (50) column to varchar (30), so using SQL above is not successful. In addition to different types, you also need to drop the column. 3 first. Remove field  alter table Name drop column field name  demo: 1alter table table_name Drop Column column_test;  Note: After dropping the field, it may cause the table query/insert operation to not be executed, you need to execute the reorg command. reorg table table_name; 4. Add a default value for a Field  alter table table name alter COLUMN field name set default value  DEMO: 1ALTER TABLE table_name ALTER COLUMN column_t EST set default   ' value ';  5. Add a field with default value demo: 1alter table table_name Add column Column_test Vachar (a) not NULL with default   ' value ';  6 . Set field default time is current time Demo: 1alter table table_name ALTER COLUMN COlumn_test set default  current date;

Db2-alter Append/delete/Reset column operations

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.