Modify the Data Type of the column corresponding to the primary key of the Oracle database table.

Source: Internet
Author: User

Modify the Data Type of the column corresponding to the primary key of the Oracle database table.

When upgrading our product from SPC100 to SPC200, because the data type of the database table column has changed, you need to write an SQL script to complete the Database Upgrade. Change the id of the primary key column in The T_MOBILE_INDVCONFIG table from varchar2 (100) to number (17 ). You can refer to the following SQL:

-- RENAME the original id column to bak_idALTER TABLE T_MOBILE_INDVCONFIG rename column id TO bak_ID; -- ADD an alter table T_MOBILE_INDVCONFIG ADD id NUMBER (17) COLUMN with the same name as the original COLUMN ); -- convert the Data Type in bak_id and save it to the newly added ID column UPDATE T_MOBILE_INDVCONFIG set id = CAST (bak_ID as number (17 )); -- delete the original alter table T_MOBILE_INDVCONFIG drop column bak_ID; -- set the new COLUMN attribute. In this example, it is set to non-empty alter table T_MOBILE_INDVCONFIG MODIFY (id number (17) not null ); -- re-create the primary key. Because the original primary key has been deleted, if the original ID column has an index, you also need to re-create alter table T_MOBILE_INDVCONFIG add constraint PK_SYS_SMSGATE primary key (ID );

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.