A primary key is a column or series of columns that uniquely identifies each individual row in a table. The PRIMARY KEY constraint is used to denote which columns in a table act as the primary key for the table. You can have only one primary key for each table. When you choose a single column as a primary key, you must have a non-NULL value for the column that is unique for the row.
If you choose a series of columns as the primary key for a table, you must have at least one of the columns contain a non-NULL unique value. Although you are not required to have a primary key for every table, it is good design practice to include a primary key in your table design.
This is so you can uniquely identify an individual row based on data values. In addition, you must have a PRIMARY KEY constraint on a parent table to allow a FOREIGN KEY constraint on a child table, as described later in this module.
The Oracle database includes a psuedo-column for every table called the ROWID.
The ROWID is a pseudo-column because it is outside the normal range of awareness for columns in a table. If you query the data dictionary tables or do a SELECT* on the table, the ROWID will not appear.
You can specifically query a table for the ROWID column in the table. The ROWID column uniquely identifies every row in an Oracle database. The ROWID never changes for a row,
unless you export the entire database and import the data. The ROWID is the fastest way to access any particular row in an Oracle database.
A pseudocolumn behaves like a table column, but is not actually stored in the table. You can select from pseudocolumns, but you cannot insert, update, or delete their values. A pseudocolumn is also similar to a function without arguments.
However, functions without arguments typically return the same value for every row in the result set, whereas pseudocolumns typically return a different value for each row.
For each row in the database, the ROWID pseudocolumn returns the address of the row. Oracle Database rowid values contain information necessary to locate a row:
The data object number of the object
The data block in the data file in which the row resides
The position of the row in the data block (first row is 0)
The data file in which the row resides (first file is 1). The file number is relative to the tablespace.
Usually, a rowid value uniquely identifies a row in the database. However, rows in different tables that are stored together in the same cluster can have the same rowid. Values of the ROWID pseudocolumn have the data type ROWID or UROWID.
Rowid values have several important uses:
They are the fastest way to access a single row.
They can show you how the rows in a table are stored.
They are unique identifiers for rows in a table.
You should not use ROWID as the primary key of a table. If you delete and reinsert a row with the Import and Export utilities, for example, then its rowid may change. If you delete a row, then Oracle may reassign its rowid to a new row inserted later. Although you can use the ROWID pseudocolumn in the SELECT and WHERE clause of a query, these pseudocolumn values are not actually stored in the database.
You cannot insert, update, or delete a value of the ROWID pseudocolumn.
Example: This statement selects the address of all rows that contain data for employees in department 20:
SELECT ROWID, last_name
WHERE department_id = 20;
The Oracle database includes a unique identifier for every row in the database through the use of a ROWID.Click the Audio button to hear about ROWIDs.
Create Table Example
In the COIN database, the CREATE TABLE command for the AUCTION table, including a PRIMARY KEY constraint, would be: