So many people asked me this question; In many interviews also I faced this question.Let’s we have a look into this.
- Primary Key and Unique key (both) uniquely identifies a row.
- Unique Key Allows 1 null column, where are Primary key will not allow null values.
- As per the DBA’s Point of view, Primary key creates a clustered index,where unique key creates non-clustered index.
I hope every one like this article.Please make some comments .
Preethy J Kamath
14 years agohiiii,
I liked this article very much bcoz i too faced the same question in different interviews.Could u plz include the practical use of primary key and unique key with an example .
and also want to know in which situation unique key is using instead of primary key.
Thanks and Regards
Preethy kamath
Varun
14 years agoHi Preethy, This is a wonderful question and also an enthusiastic one…I will explain here with a simple example.Consider a table Employee details with columns EmpID,Name and InsuranceID.Case scenario, Each Employee has an EmployeeID and InsuranceID(both are different).Here in this case EmpID and InsuranceID should be unique.EmpID can be used as a Primary key, where as InsuranceID can be used as UniqueKey.We are not using unique key instead pf Primary key.Each table should have a Primary Key.
Note : We can use only one Primary Key(ie one clustered index) in a table.
Thanks For this comment..Please keep on visiting the site…..
Dipu Joseph
14 years agoHai Varun,
Will u give me a clear reference in the coding standards have to use in SQL.( In Storeprocedures, queries, Views, triggers as well as Cursors also)
Yours Failthfully,
Dipu Joseph
Programmer
Iware Solutions, Infopark
Varun
14 years agoHi Dipu,
Thanks 4 visiting my site.I will post the coding Standards soon…..
thanking u,
Varun R
Jithin
14 years agoDear varun,
will you please describe the types of keys using in sql
Thanks and Regards,
C.H.Jithin
deep
14 years agohi varun,
IS Unique key more than one null columns