Sie sind auf Seite 1von 5

primary key unique key foreign key candidate key super key composite key secondary key integrity

key : means rules set on database tables. There are 3 types of integrity in database. 1. Entity integrity 2. Referential integrity 3. Domain integrity referential integrity key : is foreign key

Entity Integrity: no nll in pkey ( Null: no value in a key even not space. ) Referential Integrity (of reference) if a foreign key exists in a relation,
either the foreign key value must match a candidate key value of some tuple in its home relation or the foreign key value must be wholly null.

Super Key A combination of one or more columns in a table which can be used to identify a record in a table uniquely, a table can have any number of super keys. Compound Key compound key (also called a composite key or concatenated key) is a key that consists of 2 or more attributes. We can represent this buy taking a table which has the combined information of Department to Employees, Employee ID + Department ID here both of them define a record in this table, but both can make sense separately as well. Primary Key A Column in a table (which is a Simple Key) which is a Candidate Key (Uniquely identify a records in a table) and has the Constraint NOT NULL attached to it is known as a Primary Key.

Generally, but not always and need not be, Primary Key goes with a Clustered Index. Composite Primary Key (Composite Key) When we have a Primary Key of a table defined using more than one columns then it is known as a Composite Key, each columns data can be duplicated, but combined values cannot be. The columns which are participating in a composite primary key are not simple keys. For Example, we can have a situation where there is a need to define the key using first Name + last Name. Alternate Key or Secondary key An alternate key is any candidate key which is not selected to be the primary key Unique Key A column (or) combination of columns which can be used to uniquely identify a record in a table, it can have one NULL Value. Primary Key can be considered a special case of unique key with a Not Null Constraint. Generally, but not always and need not be, Unique Key goes with a Non Clustered Index. Foreign Key A column of one table points to the Primary Key column of another table to implement referential data integrity. For Example, we can have a department id column in the employee table which is pointing to department id column in a department table where it a primary key. * Candidate key - A candidate key is a field or combination of fields that can act as a primary key field for that table to uniquely identify each record in that table. * Primary key - a primary key is a value that can be used to identify a unique row in a table. Attributes are associated with it. Examples of primary keys are Social Security numbers (associated to a specific person) or ISBNs (associated to a specific book). In the relational model of data, a primary key is a candidate key chosen as the main method of uniquely identifying a tuple in a relation. * Superkey - A superkey is defined in the relational model as a set of attributes of a relation variable (relvar) for which it holds that in all relations assigned to that variable there are no two distinct tuples (rows) that have the same values for the attributes in this set. Equivalently a superkey can also be defined as a set of attributes of a relvar upon which all attributes of the relvar are functionally dependent. * Foreign key - a foreign key (FK) is a field or group of fields in a database record that points to a key field or group of fields forming a key of another database record in some (usually

different) table. Usually a foreign key in one table refers to the primary key (PK) of another table. This way references can be made to link information together and it is an essential part of database normalization

Candidate Key
A candidate is a subset of a super key. A candidate key is a single field or the least combination of fields that uniquely identifies each record in the table. The least combination of fields distinguishes a candidate key from a super key. Every table must have at least one candidate key but at the same time can have several.

As an example we might have a student_id that uniquely identifies the students in a student table. This would be a candidate key. But in the same table we might have the students first name and last name that also, when combined, uniquely identify the student in a student table. These would both be candidate keys.

In order to be eligible for a candidate key it must pass certain criteria.


It must contain unique values It must not contain null values It contains the minimum number of fields to ensure uniqueness It must uniquely identify each record in the table

Once your candidate keys have been identified you can now select one to be your primary key

Foreign Key
A foreign key is generally a primary key from one table that appears as a field in another where the first table has a relationship to the second. In other words, if we had a table A with a primary key X that linked to a table B where X was a field in B, then X would be a foreign key in B. An example might be a student table that contains the course_id the student is attending. Another table lists the courses on offer with course_id being the primary key. The 2 tables are linked through course_id and as such course_id would be a foreign key in the student table.

Simple Key
Any of the keys described before (ie primary, secondary or foreign) may comprise one or more fields, for example if firstName and lastName was our key this would be a key of two fields where as studentId is only one. A simple key consists of a single field to uniquely identify a record. In addition the field in itself cannot be broken down into other fields, for example, studentId, which uniquely identifies a particular student, is a single field and therefore is a simple key. No two students would have the same student number.

Das könnte Ihnen auch gefallen