Primary KEY constraints, unique constraints, and foreign KEY constraints for Oracle

Source: Internet
Author: User

http://www.shangxueba.com/jingyan/122163.html primary key:
1. PRIMARY KEY constraint: A table can have only one primary KEY constraint. The primary key can be a single field, or it can be multiple fields. In either case, all of its fields are not NULL.
2.Unique constraints: A table can have multiple unique constraints, and a unique field can be null.
3. Primary KEY and unique: The difference is that a table can have only one primary KEY constraint, but there may be multiple unique constraints; All fields of the primary key are not null,unique can be null; the same point is that it guarantees uniqueness.

4. Primary key, unique, and index: PRIMARY KEY constraints and UNIQUE constraints are indexed by default. When there are multiple fields for the primary key and unique, there is an index prefix problem, that is, the condition in the where statement must have a primary key or a unique first field, otherwise the index will not be used.

5. Foreign key and primary key, unique: Foreign key must be the primary key or unique index of another table (parent table). If you want to add a record, the parent table does not have an error. Conversely, if you want to delete a record in the parent table, and the child table has a record, it will also be an error. However, if you use on DELETE cascade when you create a foreign key constraint, deleting the data in the parent table does not make an error and the data that is associated directly with the table is deleted. If you want to delete the parent table, you need to add cascade constraints, at which point the foreign key of the child table is removed and the records in the table remain unchanged.

FOREIGN key:

1. A foreign key is a field that is joined between the table and another table
2. The foreign key must be a primary key in another table
3. The purpose of the foreign key is to ensure the integrity of the data. It typically includes the following: Entity integrity, which ensures that each entity is unique (implemented by a primary key).

There are 2 ways to set up Oracle primary keys:
One is to set the self-growth primary key, and the other is to generate a unique sequence;

Primary KEY constraints, unique constraints, and foreign KEY constraints for Oracle

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.