ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What is the difference between primary key and unique key not null?

this question related to database

user-image
تم إضافة السؤال من قبل Inamullah Buksh , web development , vision solution
تاريخ النشر: 2014/03/03
Rashid Anwar
من قبل Rashid Anwar , senior php developer , sparx it solution pvt ltd.

Primary Key: A primary key is a single column or combination of columns that uniquely identifies a record. None of the columns that are part of the primary key can contain a null value.A table can have multiple unique and foreign keys. However, a table can have only one primary key.

Unique Key: A unique key or primary key [is a candidate key] to uniquely identify each row in a table. It can be comprised of either a single column or multiple columns. The major difference is that for unique keys the implicit NOT NULL constraint is not automatically enforced, while for primary keys it is enforced. Thus, the values in unique key columns may or may not be NULL.

 

Differences between Primary Key and Unique Key

1. Primary Key does not accept null value whereas Unique Keys accepts null value.     

2. There will be only one primary key in a table whereas More than one unique key will be there in a table.       

3. Clustered index is created in Primary key whereas Non-Clustered index is created in unique key.       

4. Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist whereas unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values.

 

Inamullah Buksh
من قبل Inamullah Buksh , web development , vision solution

yes right answer. primary key is not allow null value but unique key allow null value.

Anas M.A
من قبل Anas M.A , SOFTWARE DEVELOPER , PEAK TECHNO LINKS PVT.LTD

Both are  used for Unique Identification of data.But the Main difference is primary key won't allow null values but unique key will  allow maximum one Null value.

mandal rushikesh
من قبل mandal rushikesh , PHP Developer , Fedobe Solutions Pvt Ltd

In a table there can be only one primary key but you can have multiple unique keys not null

 

Abdul Saboor Rana
من قبل Abdul Saboor Rana , Senior Software Engineer , trg

Primary Key: Only one/table ,unique,not null

Unique Key: can be many/table,allows null

Every primary is a unique but every unique is not primary

 

Guna Sekar
من قبل Guna Sekar

primary key=unique +not null.

unique key +not null=candidate key,

candidate keys are the nominies of primary key

المزيد من الأسئلة المماثلة