DATABASE & SQL/PLSQL

adplus-dvertising
KEYS
Previous Home Next

A database key is a attribute utilized to sort and identify data in some manner. There are many keys:

Primary key: The primary key is a attribute of a relational table uniquely identifies the each tuple of a table or each record in the table. It can either be a normal attribute that is guaranteed to be unique. Such as Social Security Number in a table with no more than one record per person.

Examples:

Imagine we have a employees table that contains a record for each employee at a organization. The employee's unique employee ID number would be a good choice for a primary key in the employees table. The employee's first and last name would not be a good choice, as there is always the chance that more than one employee might have the same name.

Foreign Key: These keys are used to create relationships between tables. Natural relationships exist between tables in most database structures.

Example:

Let’s assume that the Departments table uses the Department Name column as the primary key.

To create a relationship between the two tables, we add a new column to the Employees table called Department. We then fill in the name of the department to which each employee belongs.

We also inform the database management system that the Department column in the Employees table is a foreign key that references the Departments table.

The database will then enforce referential integrity by ensuring that all of the values in the Departments column of the Employees table have corresponding entries in the Departments table.

Candidate key, Alternate key and Composite key: table is “candidate key” for the table. We select one of the candidate key as Primary key. All candidate keys which are not chosen as "primary key" are “Alternate keys”.

The key which uniquely identify the rows of the table and which is made up of more than one attribute is called “composite key”.

Example:

In a class we have to select Class Representative. So A, B, C and D stand for that post. So A, B, C and D are candidate for Class Representative so these are candidate key. We select B as Class Representative so B is primary key and A, C and D can be Class Representative but not selected as a Class Representative so they are alternative choice. So A, C and D are alternate key. When two students of class work together in a project then they are composite key for the class.

Level of Abstraction

  1. Physical Level: Physical level is the lower level of abstraction. Its define how data is stored in database.
  2. Logical Level: The next higher level of abstraction, its describe what data be store and each logical operation done at this level, links and concept apply here.
  3. view Level: This is the higher level describe only part of entire database for a particular user.
Previous Home Next