What Is a Primary Key in Oracle?
The values of a primary key in Oracle are always unique. Additionally, the values of a primary key cannot have null (missing or unknown) values, should not change over time and should be as short as possible.
-
Identification
-
A primary key is a constraint defined on a relational database table that prevents users from entering duplicate records into the table. A primary key constraint is defined using a set of columns in the database table that uniquely identifies the records stored in a table.
Features
-
In a table that stores employee information, a possible column that uniquely identifies the employee is Social Security number, because no two employees can have the same SSN. Employee name cannot be a primary key, because more than one person can have the same name.
-
Function
-
In an Oracle database, to define the column SSN as the primary key in the employee table, one would use the following syntax:
CREATE TABLE employee (
SSN NUMBER,
emp_name VARCHAR2(30),
salary number,
CONSTRAINT employee_pk PRIMARY KEY (SSN));
Effects
-
In the above example, when SSN is defined as the primary key on the table, Oracle will create a unique index for the SSN column in the employee table. This unique index will be used to enforce the rule that a duplicate value for SSN cannot be inserted into the table.
-
References
Resources
- Photo Credit laptop with database record on 15.4" wide screen image by .shock from Fotolia.com