Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between unique key with 'not null' constraint and primary key?

I want to know difference between these two key.

When the Unique key with not null constrain in terms of how they are stored in database

and what difference are there when we making Select,Insert,Update, Delete operation for these keys.

like image 836
Bhavesh Kachhadiya Avatar asked Jan 21 '26 22:01

Bhavesh Kachhadiya


1 Answers

A primary key must be unique and non-null, so they're the same from that standpoint. However, a table can only have one primary key, while you can have multiple unique non-null keys.

Most systems also use metadata to tag primary keys separately so that they can be identified by designers, etc.

What are the differences between a primary key and a Unique key with not null constrain in terms of how they are stored in database

If both are either CLUSTERED or NON CLUSTERED then the only difference is metadata in most systems to tag a index as a PK.

what difference are there when we making Select,Insert,Update, Delete operation for these keys

None.

like image 189
D Stanley Avatar answered Jan 24 '26 18:01

D Stanley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!