0% found this document useful (0 votes)
360 views

Integrity and Domain Constraints

This document discusses database constraints. It defines constraints as rules enforced on data columns to maintain integrity. The main types of constraints covered are NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY and DEFAULT. Syntax for applying constraints in SQL while creating tables is shown. Examples of each constraint type are provided. In conclusion, constraints help define valid data types and values for columns and ensure relations between tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
360 views

Integrity and Domain Constraints

This document discusses database constraints. It defines constraints as rules enforced on data columns to maintain integrity. The main types of constraints covered are NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY and DEFAULT. Syntax for applying constraints in SQL while creating tables is shown. Examples of each constraint type are provided. In conclusion, constraints help define valid data types and values for columns and ensure relations between tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Database Presentation

Prepared By
Aaditya Manandhar
BIM 4th semester
Section A Roll no 1

Database Presentation 7/19/2018 1


 Introduction to constrains
 Syntax
 Constraintsused in SQL
 Use of Constraints
 About Integrity Constraints and its Type
 About Domain Constraints and its Type

Database Presentation 7/19/2018


2
 Rules enforced on data columns on table.
 Purpose is to maintain data integrity
 Used to limit the type of data that goes into a table
 Other words, specifies the rules for the data in table
 Any violation between constraints and data it prevents it

 Syntax of SQL constraints while creating Table is shown


in next slide

Database Presentation 7/19/2018


3
 CREATE TABLE table_name
(
column_name1 data_type(size) constraint_name,
column_name2 data_type(size) constraint_name,
column_name3 data_type(size) constraint_name,
....
);

Database Presentation 7/19/2018


4
 NOT NULL- Indicates that a column cannot store NULL value

 UNIQUE – Ensures that each row for a column must have a unique
value

 PRIMARY KEY- Uniquely Identify the tuple

 FOREIGN KEY- referential Integrity of data in one table to match


value in next table

 DEFAULT- Specifies the default value for column

Database Presentation 7/19/2018


5
 Protect the integrity of the database

 To tell DBMS about the data

Database Presentation 7/19/2018


6
 Also known as Referential constraints
 Ensures changes made to database do not result loss of data
consistency
 Impose restriction on allowable data in database

Database Presentation 7/19/2018


7
1.Entity Integrity Constraints

2. Referential Integrity Constraints

Database Presentation 7/19/2018


8
 Refers about Primary key in database
 Unique key to identify the tuple
 States that no attribute of primary key is null
 i.e. primary key cannot be a null value
 States that every relation must have a primary
key

Database Presentation 7/19/2018


9
Database Presentation 7/19/2018
10
 every value of one column of relation to exist as
value of another column in different
table(relation)
 States about the foreign key
 Defines the relation between the tables
 Foreign key must reference a valid primary
key(Parent table)

Database Presentation 7/19/2018


11
Database Presentation 7/19/2018
12
 Specifies what set of values an attribute can take
 User defined constraints

 They are elementary form of integrity constraints


 Test values inserted in the database and test queries to
ensure that comparison makes sense

 Data types associated are integer, character, string,


date, time etc
 Example: Age cannot be negative value or alphabets

Database Presentation 7/19/2018


13
Database Presentation 7/19/2018
14
 NOT NULL Constraints
 UNIQUE Constraints
 Default Constraints

Database Presentation 7/19/2018


15
 Strictthe column not to accept null value
 Enforces a field to contain value
 Cannot modify record without adding
value

Database Presentation 7/19/2018


16
 CREATE TABLE PersonsNotNull
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

 Here P_id must have some value which is of integer type and
 LatName should have character type value

Database Presentation 7/19/2018


17
 Works as like primary key
 Uniquely identify each record in relation
 Many UNIQUE per table but only one
primary key

Database Presentation 7/19/2018


18
 CREATE TABLE Persons
(
P_Id int NOT NULL UNIQUE,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

 Here P_id must be a unique integer data type

Database Presentation 7/19/2018


19
Database Presentation 7/19/2018
20
 Assign default value to field
 Value will only be assignesd when no
other value is specifeid
 Written as:
 City varchar(255) DEFAULT 'Sandnes'

Database Presentation 7/19/2018


21
 CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255) DEFAULT ‘Kathmandu'
);

 Value ‘Kathmandu’ will be assigned if no value is given


in City column

Database Presentation 7/19/2018


22
 Constraints defines way to insert data in
relation
 Helps us to know what type of data we
insert in relation
 Uniquely identifying records
 Create relation between tables

Database Presentation 7/19/2018


23
 www.tutorialspoint.com/sql/sql-constraints.htm

 beginnersbook.com/2015/04/constraints-in-dbms/

 www.w3schools.com/sql/sql_constraints.asp

 http://www.edugrabs.com/types-of-constraints-in-dbms-or-
relational-constraints/

 https://www.youtube.com/watch?v=zvYU9vlvDNY

 https://en.wikipedia.org/wiki/Entity_integrity

Database Presentation 7/19/2018


24
Database Presentation 7/19/2018
25

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy