Add Oracle Constraints

Source: Internet
Author: User

Run the edit D:/a. SQL command to edit the SQL statement in a text file. Run @ D:/a. SQL to run the text file you just edited.

Create is creation, alter is modification, drop is Deletion

SQL plus is used in the following operations. If an error occurs, you can use the drop... command to delete it:


Add primary key:

Based on the primary key of one column: alter table test add constraint pk_test primary key (ename );
The Union primary key based on multiple columns: alter table test add constraint pk_test primary key (ename, birthday );

ID of the auto-increment type:

First create sequence:



Minvalue 1 maxvalue 999999999

Increment by 1

Start with 1

Nocycle noorder nocache;

Then create a trigger:

Create trigger trigger_name

Before insert on table_name

For each row

Begin

Select sequence_name.nextval into: New. ID from dual;

End;

Delete sequence: drop sequence emergency_sche_id;

Delete trigger: Drop trigger emergency_event_id_incret;


Create a foreign key constraint:

Alter table students

Add constraint fk_students_state
Foreign key (state) References state_lookup (State );

Reference page: http://wallimn.iteye.com/blog/703921




 

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.