Get the App
SLTechnology News&Howtos  ›  Database  › 

Oracle unique indexes, unique constraints, relationships between primary keys

Shulou Source: shulou.com Published: 2022-06-01 08:06:29 10月25日 Update

A primary key (primary key) is one or more fields in a table whose values are used to uniquely identify a record in the table. In the relationship between two tables, the primary key is used to reference a specific record from another table in one table, a unique key, a part of the table definition. The primary key of a table can be composed of multiple keywords, and the primary key cannot contain null values. When a primary key is created in oracle, a unique index is automatically generated, and the unique index can be looked up in the user_indexes view.

Create two tables with the same table structure. Test_1 specifies C1 as the primary key, test_2 adds NOT NULL and UNIQUE constraints to C1, and no primary key is specified.

View the index of test_1,test_2

View the constraints of test_1,test_2

A unique index that does not allow rows with the same index value, thus prohibiting duplicate indexes or key values. The system checks for duplicate key values when creating the index and each time you add data using an INSERT or UPDATE statement.

Create the test_5 table and add a unique index to C1.

View the index on test_5.

View the constraints on the test_5.

Unique constraints guarantee that the data in a field or set of fields is unique compared to the data in other rows in the table. A unique constraint is created in oracle and a unique index is generated accordingly.

Create the table test_6 and add unique constraints to the C1 column.

View the constraints on the test_6.

View the index on test_6.

Tags: Index field data same key keyword multiple medium check generate two landmark system structure automatic generation view statement guarantee connection Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology vpn Shulou Tech Info NVidia