Oracle Data Integrity Maintenance

Source: Internet
Author: User

1. Delete Constraints
Alter table table_name drop constraint constraint_name;
2. Create a primary key
Alter table table_name add constraint constraint_name primary key (column_name1, column_name2 );
3. Create a unique constraint
Alter table table_name add constraint constraint_name unique (column_name1, column_name2 );
4. Create a foreign key constraint
Alter table table_name1 add constraint constraint_name foreign key (column_name1) references table_name2 (column_name1 );
Enable/disable: Restrict/not restrict new data
Novalidate/validate: Incorrect/verification of old data
Alter table table_name add constraint constraint_name check (column_name like 'B %') enable/disable novalidate/validate;
5. Modify constraints, delay verification, and commit Verification
Alter table table_name modify constraint constraint_name initially deferred;
6. Modify constraints and verify now
Alter table table_name modify constraint constraint_name initially immediate;
7. Set constraints delay/verify now
Alter session set constraints = deferred/immediate;
8. Delete constraints when deleting a table
Drop a primary key table with foreign keys and cascade deletion with cascade constraints Parameters
Drop table table_name cascade constraints;
9. When the truncate foreign key table is used, the foreign key is set to invalid first, and then truncate;
Truncate table table_name;
Invalid constraint settings
Alter table table_name disable constraint constraint_name;
Alter table table_name enable novalidate constraint constraint_name;

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.