what is sql-constraints | type of SQL Constraints

7/14/2021
All Articles

#sql #sqlconstraints #typeConstraints #oracleConstraints

what is sql-constraints |  type of SQL Constraints

What is Sql Constraints ?

  • Constraint are used to implement business rules.
  • Used to define rules to allow or restrict what values can be stored in columns.
  • The purpose of inducing constraints is to enforce integrity of database.

Type Of Constraints

  • NOT NULL
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY or Referential Key
  • CHECK

Below details description on Type of SQL Constraints

In table level constraints are declared after declaring all columns. Use table level when more than one column participates in constraint declaration.

NOT NULL:

NOT NULL constraint allows to specify that a column can not contain any NULL value.
 NOT NULL can be used to CREATE and ALTER a table. 

 

UNIQUE :

The UNIQUE constraint does not allow to insert a duplicate value in a column. 
More than one UNIQUE column can be used in a table.

 

PRIMARY KEY:


A PRIMARY KEY constraint enforces the table to accept unique data for a specific column 
and this constraint create a unique index for accessing the table faster. 

 

FOREIGN KEY:


A FOREIGN KEY in L creates a link between two tables by one specific column of both table.
 The specified column in one table must be a PRIMARY KEY 
 and referred by the column of another table known as FOREIGN KEY.

 

CHECK:  


A CHECK constraint controls the values in the associated column. 
The CHECK constraint determines whether the value is valid 
or not from a logical expression.  

 

This is Example primary key Constrains:


CREATE TABLE Student(roll_no varchar(7),name varchar(20) ,address
varchar(50) ,tot_marks int, branch varchar(6), PRIMARY KEY(roll_no));

 

Conclusion :

Here we Learn What is Sql Constarints ?

What is type of SQL Constraints?

It Is clear we are using constraints to restrict certain activity on data of Table.

If You have any doubt reach out to us

 

 

Article