Record non-empty constraints for deleting Oracle table fields at one time

Source: Internet
Author: User
Tags oracle documentation

Record the non-null constraint for deleting Oracle table fields at a time. A table structure specifies that a field (such as cno) is not null, and the check not null constraint is added. Now we need to remove the not null constraint so that the cno field can be inserted with a null value. The following statement is executed:

SQL code 1. alter table tableName drop constraints not_null_cons_cno; 2. alter table tableName modify cno null;

 

After the statement is executed, the null value cannot be inserted. The following error is reported: ORA-01451: column to be modified to NULL cannot be modified to NULL queries the Oracle documentation, which is described as follows: Cause: the column may already allow NULL values, the not null constraint is part of a primary key or check constraint. action: if a primary key or check constraint is enforcing the not null constraint, then drop that constraint. then I found that this field and other fields constitute a unique composite index. So I modified this index and deleted the cno field from it.
1. delete the primary key. SQL code alter table tableName drop constraints pk_tableName; 2. delete a unique index; SQL code drop index un_idx_table_name; 3. create a primary key (excluding the cno field); SQL code alter table tableName add constraint PK_tableName primary key (DNO, TNO, YEAR, PNO );

 

4. Create a unique index (excluding the cno field ).
SQL code create unique index ix_tableName on tableName (DNO, TNO, YEAR, PNO );

 

Step 1 reported the error: ORA-02437: cannot validate (TBOSDATA. PK_VOU_NUM)-primary key violated which indicates that the primary key or unique key has duplicate records. (My uniqueness constraints apply to dno, tno, cno, year, And pno fields. Find duplicate records:
SQL code select * from test vnt where (vnt. dno, vnt. tno, vnt. year, vnt. pno) in (select t. dno, t. tno, t. year, t. pno from test t group by t. dno, t. tno, t. year, t. pno having count (*)> 1) order by dno, tno, year, pno;

 

Delete or modify the repeat record, and execute the above 3, 4 again.

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.