Oracle Delete Table PRIMARY KEY statement

Source: Internet
Author: User

Delete Nameless PRIMARY KEY statement:

SELECT *  from WHERE = ' Table name ' ; ALTER TABLE DROP CONSTRAINT primary Key name;

The above statement needs to be manual, how to do it automatically? See below:

CREATE OR REPLACE FUNCTIONDel_table_constraint (tb_nameVARCHAR2, Field_nameVARCHAR2)   RETURN  Number isCon_count Number; Con_nameVARCHAR2( +);BEGINCon_name:= "'; Con_count:= 0; SELECT COUNT(DISTINCTconstraint_name) intoCon_count fromUser_cons_columnsWHEREtable_name= UPPER(Tb_name) andcolumn_name= UPPER(Field_name) andROWNUM= 1; IFCon_count> 0    Then      SELECT DISTINCTconstraint_name intoCon_name fromUser_cons_columnsWHEREtable_name= UPPER(Tb_name) andcolumn_name= UPPER(Field_name) andROWNUM= 1; EXECUTEIMMEDIATE'ALTER TABLE' ||Tb_name|| 'drop Constraint' ||Con_name; END IF; RETURN 0;END;

This execution

DECLARE    a   number; BEGIN    A:= del_table_constraint (' table name ' field name ' ); END ; /

Oracle Delete Table PRIMARY KEY statement

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.