MariaDB Unique Index and Null Values
Its Allows one NULL value per unique indexed column, but NULL is not considered equal to any other value. Or we can say that, the multiple rows of that column can have NULL values. It Supports a fast search for unique values in the indexed columns. However, other then non-NULL values, each rows should must be unique value.
Example:
# Creating a table with a unique index on the 'studentId' column
//creating a table
CREATE TABLE students
(
studentId INT UNIQUE,
studentName VARCHAR(50)
);
//inserting data into the table
# Inserting data with NULL values in 'studentId'
INSERT INTO students (studentId, studentName) VALUES
(1, ' Student1 '),
(2, ' Student2 '),
(NULL, ' Student3 '),
(NULL, ' Student4 ');
Explanation: In the example, the unique index on the studentId column allows multiple NULL values. The uniqueness constraint is only applied to non-NULL values.
Output:
MariaDB Unique Index
MariaDB is a fast, scalable, open-source community-supported relational database management system that’s also an enhanced version of MySQL. Content management systems (CMS) are a key application of MariaDB. A CMS is a publication system through which web creators can push and manage large quantities of content on a website. In this article, we will understand the Unique Index in MariaDB along with its syntax, examples, and so on.
Contact Us