Recent Post

6/recent/ticker-posts

Constraints in SQL

 Hello Techie Guys.

In this article discuss about the Constraints in SQL. Why it is required for any developer before create the table or fully database for our projects or application. Why it's very import phase for any type database layout or design for a our application or project.

Constraints

Constraints means in SQL We are applying some condition or restriction before any type of data insertion or updating on database. When we wants to insert or update the data in database so we are checking some conditions when we create the table so we define the condition.

SQL Constraints

  1. NOT NULL
  2. Unique
  3. Primary Key
  4. Foreign Key
  5. Check
  6. Default

NOT NULL-  If we create a table with NOT NULL  Constraints. So that mean in this particular column value we can not empty inserted because that's show error so please see in below picture.

First We create a table with Not Null Constraints:-

Picture for create table with NOTNULL Constraints

Picture for create table with NOTNULL Constraints
Now Try to insert with null value
Try with NULL Values

Showing Error when we try to insert data with null values

Unique - If we create or apply with any column unique constraint that's mean this column all row values is unique. Below images show the output.

Now create table with Unique constraints
Create table with Unique constraints

Create table with Unique constraints
Now try to some data insert with unique constraints
Insert data with unique constraints
Insert data with unique constraints

Show the OUTPUT below Picture


Explanation-  Here first two insertion query is different value with Email column but last two insertion query with same first two insertion query. so that's why below two row insertion failed. 





Post a Comment

0 Comments