12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Managing Tables4.2.5.1 Primary KeyA primary key requires that a column (or combination of columns) be the uniqueidentifier of the row and ensures that no duplicate rows exist. A primary key columncannot contain NULL values. Each table can have only one primary key.Use the following guidelines when selecting a primary key:■ Whenever practical, create a sequence number generator to generate uniquenumeric values for your primary key values.■■■■■Choose a column whose data values are unique, because the purpose of a primarykey is to uniquely identify each row of the table.Choose a column whose data values are never changed. A primary key value isonly used to identify a row in the table, and its data should never be used for anyother purpose. Therefore, primary key values should rarely or never be changed.Choose a column that does not contain any nulls. A PRIMARY KEY constraint, bydefinition, does not allow any row to contain a null in any column that is part ofthe primary key.Choose a column that is short and numeric. Short primary keys are easy to type.Minimize your use of composite primary keys. A composite primary keyconstraint applies to more than one column. Although composite primary keys areallowed, they do not satisfy all of the other recommendations. For example,composite primary key values are long and cannot be assigned by sequencenumbers.4.2.5.2 Unique KeyA unique key requires that every value in a column be unique. That is, no two rowscan have duplicate values in a specified column or combination of columns.Choose columns for unique keys carefully. The purpose of these constraints is differentfrom that of primary keys. Unique key constraints are appropriate for any columnwhere duplicate values are not allowed. Primary keys identify each row of the tableuniquely, and typically contain values that have no significance other than beingunique. In the employees table, the email column has a unique key constraintbecause it is important that the emails for each employee are unique. Note that theemail column has a NOT NULL constraint.Some examples of good unique keys include:■ An employee social security number where the primary key might be theemployee number■■■A truck license plate number where the primary key might be the truck numberA customer phone number, consisting of the two columns area_code andlocal_phone where the primary key might be the customer numberA department name and location where the primary key might be the departmentnumber4.2.5.3 Check ConstraintA check constraint requires that a column (or combination of columns) satisfy acondition for every row in the table. A check constraint must be a boolean expressionthat is evaluated using the column value about to be inserted or updated to the row.Database Objects: Usage Information 4-5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!