0

Types of keys

15th Dec 2016, 7:10 AM
Akwin Lopez
Akwin Lopez - avatar
2 Respostas
0
There are five types of keys in database which is as follows - Candidate key Primary Key Foreign Key Alternate Key Composite Key Example: STUDENT {SID, FNAME, LNAME, COURSEID} Here in STUDENT table keys are: Candidate keys are SID or FNAME+LAME Primary Key: SID Foreign Key: COURSEID Alternate Key: FNAME+LAME Composite Key: FNAME+LAME Candidate Key Candidate keys are those keys which is candidate for primary key of a table. In simple words we can understand that such type of keys which full fill all the requirements of primary key which is not null and have unique records is a candidate for primary key. So thus type of key is known as candidate key. Every table must have at least one candidate key but at the same time can have several. Primary Key Such type of candidate key which is chosen as a primary key for table is known as primary key. Primary keys are used to identify tables. There is only one primary key per table. In SQL Server when we create primary key to any table then a clustered index is automatically created to that column. Foreign Key Foreign key are those keys which is used to define relationship between two tables. When we want to implement relationship between two tables then we use concept of foreign key. It is also known as referential integrity. We can create more than one foreign key per table. 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. Alternate Key If any table have more than one candidate key, then after choosing primary key from those candidate key, rest of candidate keys are known as an alternate key of that table. Like here we can take a very simple example to understand the concept of alternate key. Suppose we have a table named Employee which has two columns EmpID and EmpMail, both have not null
15th Dec 2016, 7:11 AM
Akwin Lopez
Akwin Lopez - avatar
0
he UNIQUE constraint uniquely identifies each record in a database table. UNIQUE Key The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it. Note that you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.
15th Dec 2016, 7:12 AM
Akwin Lopez
Akwin Lopez - avatar