0% found this document useful (0 votes)
18 views1 page

Day 3 Notes

Excel

Uploaded by

cocomelon1650
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Day 3 Notes

Excel

Uploaded by

cocomelon1650
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

CONSTRAINTS

Constraints are the rules that we can apply on the type of data in a table.
That is, we can specify the limit on the type of data that can be stored in
a particular column in a table using constraints. It ensures the reliability,
consistency and accuracy of the data in the table. It helps create
meaningful databases, as there always some restrictions and rules that
you would want to impose on the data being entered in the database. If
there is any violation between the constraint and the data action, the
action is aborted.
The available constraints in SQL are:

 NOT NULL: This constraint tells that we cannot store a null


value in a column. That is, if a column is specified as NOT NULL
then we will not be able to store null in this particular column
any more.
 UNIQUE: This constraint when specified with a column, tells
that all the values in the column must be unique. That is, the
values in any row of a column must not be repeated.
 PRIMARY KEY: A primary key is a field which can uniquely
identify each row in a table. And this constraint is used to
specify a field in a table as primary key. (not null + unique)
 FOREIGN KEY: A Foreign key is a field which can uniquely
identify each row in another table. And this constraint is used to
specify a field as foreign key. (ER diagram)
FOREIGN KEY constraints enforce referential integrity, which
essentially says that if column value A refers to column value B,
then column value B must exist.
 CHECK: This constraint helps to validate the values of a column
to meet a particular condition. That is, it helps to ensure that
the value stored in a column meets a specific condition.
 DEFAULT: This constraint specifies a default value for the
column when no value is specified by the user.

How to specify constraints?


We can specify constraints at the time of creating the table using
CREATE TABLE statement. We can also specify the constraints after
creating a table using ALTER TABLE statement.

You might also like