B
bluesea07
Unregistered / Unconfirmed
GUEST, unregistred user!
Primary Keys
Every row in a table should have some column (or set of columns) that uniquely identifies it. A table containing customers might use a customer number column for this purpose, whereas a table containing orders might use the order ID. An employee list table might use an employee ID or the employee social security number column.
Primary Key A column (or set of columns) whose values uniquely identify every row in a table.
This column (or set of columns) that uniquely identifies each row in a table is called a primary key. The primary key is used to refer to a specific row. Without a primary key, updating or deleting specific rows in a table becomes extremely difficult as there is no guaranteed safe way to refer to just the rows to be affected.
Always Define Primary Keys Although primary keys are not actually required, most database designers ensure that every table they create has a primary key so that future data manipulation is possible and manageable.
Any column in a table can be established as the primary key, as long as it meets the following conditions:
_ No two rows can have the same primary key value.
_ Every row must have a primary key value (primary key columns may not allow NULL values).
_ Values in primary key columns can never be modified or updated.
_ Primary key values can never be reused. (If a row is deleted from the table, its primary key may not be assigned to any new rows in the future.)
Primary keys are usually defined on a single column within a table. But this is not required, and multiple columns may be used together as a primary key. When multiple columns are used, the rules listed above must apply to all columns that make up the primary key, and the values of all columns together must be unique (individual columns need not have unique values).
There is another very important type of key called a foreign key, but I'll get to that later on in Lesson 12, "Joining Tables."
Every row in a table should have some column (or set of columns) that uniquely identifies it. A table containing customers might use a customer number column for this purpose, whereas a table containing orders might use the order ID. An employee list table might use an employee ID or the employee social security number column.
Primary Key A column (or set of columns) whose values uniquely identify every row in a table.
This column (or set of columns) that uniquely identifies each row in a table is called a primary key. The primary key is used to refer to a specific row. Without a primary key, updating or deleting specific rows in a table becomes extremely difficult as there is no guaranteed safe way to refer to just the rows to be affected.
Always Define Primary Keys Although primary keys are not actually required, most database designers ensure that every table they create has a primary key so that future data manipulation is possible and manageable.
Any column in a table can be established as the primary key, as long as it meets the following conditions:
_ No two rows can have the same primary key value.
_ Every row must have a primary key value (primary key columns may not allow NULL values).
_ Values in primary key columns can never be modified or updated.
_ Primary key values can never be reused. (If a row is deleted from the table, its primary key may not be assigned to any new rows in the future.)
Primary keys are usually defined on a single column within a table. But this is not required, and multiple columns may be used together as a primary key. When multiple columns are used, the rules listed above must apply to all columns that make up the primary key, and the values of all columns together must be unique (individual columns need not have unique values).
There is another very important type of key called a foreign key, but I'll get to that later on in Lesson 12, "Joining Tables."