Modifying the data type of the primary key corresponding column of an Oracle database table

Source: Internet
Author: User

When we upgraded our products from SPC100 to SPC200, we needed to write SQL scripts to complete the database upgrade because the data types of the database table columns changed. The primary key column ID for table t_mobile_indvconfig needs to be changed from VARCHAR2 (100) to Number (17). You can refer to the following SQL:

--Name the original ID rename bak_idalter table t_mobile_indvconfig RENAME column ID to bak_id;--add a column with the same name as the original column ALTER TABLE T_mobile_ Indvconfig ADD ID Number (17); --Convert the data in bak_id to the newly added ID column update t_mobile_indvconfig SET id = CAST (bak_id as number (17));--delete the original column alter TABLE T_mobile_ Indvconfig DROP column bak_id;--sets the new column property, where the example is set to non-null alter TABLE t_mobile_indvconfig MODIFY  (ID number (n) not NULL);-- Rebuilding the primary key, because the original ID column has been deleted, also needs to be rebuilt alter TABLE t_mobile_indvconfig  ADD CONSTRAINT pk_sys_smsgate PRIMARY key (ID);

Modifying the data type of the primary key corresponding column of an Oracle database table

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.