What are constraints in SQL?

Shripal Jain
Shripal Jain

Posted On: Dec 17, 2020

 

Constraints are the rules or limits that we can apply to the type of data in a table

The available constraints in SQL are:

NOT NULL: This constraint tells us that we cannot store a null value in a column.

UNIQUE: This constraint when specified with a column, tells that all the values in the column must be unique. 

PRIMARY KEY: A primary key is a field that can uniquely identify each row in a table. Typically, used to specify a field in a table as the primary key.

FOREIGN KEY: A Foreign key is a field that can uniquely identify each row in another table.

CHECK: This constraint helps to validate the values of a column to meet a particular condition. 

DEFAULT: This constraint specifies a default value for the column when no value is specified by the user.

For instance, 

 REATE TABLE Student
(
ID int(6) NOT NULL,
NAME varchar(10) NOT NULL,
ADDRESS varchar(20)
);

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    HCL freshers interview questions

    What is an array?

    In programming, Array is a collection of similar types of values in a single unit. Array stores data in a contiguous memory location....

    HCL freshers interview questions

    Explain ISO/OSI Model and it's Layers?

    The OSI model is a networking model for understanding and designing a network architecture that would be flexible, robust, and interoperable. Communication between different systems without requiring ...

    HCL freshers interview questions

    What are four pillars of OOPS?

    The four pillars of OOPs are as follows:Inheritance Abstraction Encapsulation Polymorphism ...