What is Database Constraint?
This article describes about the database constraint in SQL. Summary of the article:
- What is Database Constraint?
- Types of Database constraints
- How to make a Great Primary Key?
- Primary Key Constraint
- Foreign Key Constraint
- Unique Key Constraint
- Not null Constraint
- Check Constraint
What is Database Constraint?
Database constraint is user-defined structures that express the behaviors of column. It is used to protect wrong entry.
Database constraint is user-defined structures that express the behaviors of column. It is used to protect wrong entry.
Types of Database constraints
There are five types of database constraints. Such:
There are five types of database constraints. Such:
- Primary Key Constraint
- Foreign Key Constraint
- Unique Key Constraint
- Not null Constraint
- Check Constraint
Primary Key Constraint
A column value will be unique among all the rows in a table. It does not allow any null value. Therefore, a primary key constraint has the behaviors of both Not Null and Unique Key Constraints.
A column value will be unique among all the rows in a table. It does not allow any null value. Therefore, a primary key constraint has the behaviors of both Not Null and Unique Key Constraints.
Foreign Key Constraint
We can’t insert a foreign key value which is not present in the primary key column of that foreign key.
We can’t insert a foreign key value which is not present in the primary key column of that foreign key.
Unique Key Constraint
A column value will be unique among all the rows in a table. It allows only a single Null value in that column. Depending on the design, a table may have more than one unique key constraint.
A column value will be unique among all the rows in a table. It allows only a single Null value in that column. Depending on the design, a table may have more than one unique key constraint.
Not null Constraint
It makes a column mandatory. This means you can’t insert a row in the table without providing a valid data.
It makes a column mandatory. This means you can’t insert a row in the table without providing a valid data.
Check Constraint
Check Constraints are table-level constraint. It doesn’t make the column mandatory.
Check Constraints are table-level constraint. It doesn’t make the column mandatory.
That’s all about the constraint of a database.
No comments