SQL constraints

What is SQL?, Purposes of SQL, SQL Features, Users of SQL, SQL for Database Developers, SQL Database Testers and Database Administrators. Database Fundamentals, Database Management Systems, and Relational Database Management Systems.
Post Reply
AyubHussain
Posts: 142
Joined: Fri Nov 23, 2018 2:48 am

SQL constraints

Post by AyubHussain » Mon Dec 03, 2018 6:11 am

Why do we use SQL constraints? Which constraints we can use while creating database in SQL?

dsusmitha
Posts: 62
Joined: Fri Nov 23, 2018 2:51 am

Re: SQL constraints

Post by dsusmitha » Mon Dec 03, 2018 6:12 am

Constraints are used to set the rules for all records in the table. If any constraints get violated then it can abort the action that caused it.

Constraints are defined while creating the database itself with CREATE TABLE statement or even after the table is created once with ALTER TABLE statement.

There are 5 major constraints are used in SQL, such as

NOT NULL: That indicates that the column must have some value and cannot be left null

UNIQUE: This constraint is used to ensure that each row and column has unique value and no value is being repeated in any other row or column

PRIMARY KEY: This constraint is used in association with NOT NULL and UNIQUE constraints such as on one or the combination of more than one columns to identify the particular record with a unique identity.

FOREIGN KEY: It is used to ensure the referential integrity of data in the table and also matches the value in one table with another using Primary Key

CHECK: It is used to ensure whether the value in columns fulfills the specified condition

srini
Posts: 76
Joined: Thu Jan 03, 2019 3:58 am

Re: SQL constraints

Post by srini » Thu Jan 10, 2019 6:32 am

Constraints are the rules enforced on the data columns of a table. These are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the database.

NOT NULL Constraint − Ensures that a column cannot have NULL value.
DEFAULT Constraint − Provides a default value for a column when none is specified.
UNIQUE Constraint − Ensures that all values in a column are different.
PRIMARY Key − Uniquely identifies each row/record in a database table.
FOREIGN Key − Uniquely identifies a row/record in any of the given database table.
CHECK Constraint − The CHECK constraint ensures that all the values in a column satisfies certain conditions.
INDEX − Used to create and retrieve data from the database very quickly.

Post Reply

Return to “SQL Fundamentals”