Difference Between Primary Key and UNIQUE Constraint
Primary Key and Unique Constraint , both are used in relational database to ensure uniqueness but they are some different/unique aspects in both. Lets discuss some of these aspects :-
- Primary key do not allows NULL values but on the other hand UNIQUE constraint allows NULL value.
- We can have only one primary key in our table, on the other hand we can have more than one UNIQUE columns in our table.
Null Values in UNIQUE Columns
UNIQUE columns cannot accepts duplicate values however it can accept more than one null values. It has shown in the below example.
INSERT INTO w3wiki(user_id,name,rank,overall_score,monthly_score)
VALUES (205,'Harsh',NULL,1900,20);
INSERT INTO w3wiki(user_id,name,rank,overall_score,monthly_score)
VALUES (200,'Karan',NULL,1905,10);
Output:
SQLite UNIQUE Constraint
SQLite is a lightweight relational database management system (RDBMS). It requires minimal configuration and it is self-contained. It is an embedded database written in C language. It operates a server-less, file-based database engine making it a good fit for mobile applications and simple desktop applications. It supports standard SQL syntax. In this article, we are going to cover all the necessary points of UNIQUE constraint. This article will cover every possible use of UNIQUE constraints.