[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Different between Pimary key and Alternative Key

Posted on 2011-10-11
3
Medium Priority
?
245 Views
Last Modified: 2012-05-12
What's the difference between Pimary key and altnerative key ? Under what situtation should I need to define an alternative key ?

Thanks
0
Comment
Question by:AXISHK
3 Comments
 
LVL 2

Accepted Solution

by:
the_o earned 1000 total points
ID: 36947720
Morning.

A candidate key is one that can identify each row of a table uniquely.
Generally a candidate key becomes the primary key of the table.

If the table has more than one candidate key, one of them will become the primary key, and the rest are called alternate keys.

A key formed by combining at least two or more columns is called composite key.

Hope this sheds some light on the subject. If so, please mark as answer.
Thanks
Theo
0
 
LVL 9

Assisted Solution

by:pritamdutt
pritamdutt earned 1000 total points
ID: 36947730
To put it simply take an example, look at the Customer table below:

create table Customer ( ;
CustKey      I primary key, ;
CustID      c(8) unique, ;
CustName c(30), ;
...)


CustKey must be unique because it is the PK for the table. However, the CustID must also be unique because it is used by the users to locate a specific customer record. This causes the CustID field to be an AlternateKey.

Another example for the need of alternate key: A hotel room reservation table may have a primary key "reservation_number". However, since no room can be reserved twice on the same day there are also alternate keys of (room_number, from_date) and (room_number,end_date).

Hope this helps!
0
 

Author Closing Comment

by:AXISHK
ID: 36947756
Tks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question