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

Fundamentals of Database Systems: (SQL - Iv)

[1] Contributor table: Primary key on contributor id [2] Code-Group table: Foreign key on contributor id references Contributor, Primary key on code group [3] Code-Group table: Check constraint that count submissions is greater than or equal to 0

Uploaded by

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

Fundamentals of Database Systems: (SQL - Iv)

[1] Contributor table: Primary key on contributor id [2] Code-Group table: Foreign key on contributor id references Contributor, Primary key on code group [3] Code-Group table: Check constraint that count submissions is greater than or equal to 0

Uploaded by

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

Outline Integrity Control Basic Integrity Preservation Problems

Fundamentals of Database Systems


[SQL – IV]

Malay Bhattacharyya

Assistant Professor

Machine Intelligence Unit


Indian Statistical Institute, Kolkata
December, 2020
Outline Integrity Control Basic Integrity Preservation Problems

1 Integrity Control

2 Basic Integrity Preservation


Fundamentals
Primary Key
Foreign Key
Nullity Check
General Check

3 Problems
Outline Integrity Control Basic Integrity Preservation Problems

Basics

The term integrity in databases refers to the accuracy and


consistency of data. The integrity control can set the following
types of constraints on the data items:
Basic integrity constraints
Advanced integrity constraints
Outline Integrity Control Basic Integrity Preservation Problems

Basic integrity constraints

The basic integrity constraints are of following four types:


Defining the primary key constraint
– specified as primary key (A1 , . . . , Ak )
Defining the foreign key constraint
– specified as foreign key (Ap , . . . , Aq ) references R
Defining the null constraint
– specified as not null
Defining the check constraint
– specified as check <predicate>
Outline Integrity Control Basic Integrity Preservation Problems

Consider a relational schema

BRANCH = hbranch id : integer , branch name :


string , branch city : string , assets : reali
CUSTOMER = hcustomer id : integer , customer name :
string , customer street : string , customer city :
string , account number : integer i
LOAN =
hloan number : integer , branch name : string , amount : reali
BORROWER =
hcustomer name : string , loan number : integer i
ACCOUNT = haccount number : integer , branch name :
string , balance : reali
DEPOSITOR =
hcustomer name : string , account number : integer i
Outline Integrity Control Basic Integrity Preservation Problems

Basic integrity constraints – primary key

The table BRANCH can be created with the following SQL query:

create table BRANCH(


branch id int(10) not null,
branch name varchar(30),
branch city varchar(30),
assets float(20,2),
primary key (branch id)
);

Note: Multiple attributes can be defined (by putting them


together as arguments separated by comma) as the primary key.
Outline Integrity Control Basic Integrity Preservation Problems

Basic integrity constraints – foreign key

The table CUSTOMER can be created with the following SQL query:

create table CUSTOMER(


customer id int(20) not null,
customer name varchar(30),
customer street varchar(30),
customer city varchar(30),
account number int(20),
primary key (customer id),
foreign key (account number) references Account
);
Outline Integrity Control Basic Integrity Preservation Problems

Basic integrity constraints – null

The table LOAN can be created with the following SQL query:

create table LOAN(


loan number int(10) not null,
branch name varchar(30),
amount float(15,2)
);
Outline Integrity Control Basic Integrity Preservation Problems

Basic integrity constraints – check

It can be ensured that a predicate on the attributes (say the


amount is non-negative) must be satisfied by every tuple in the
table LOAN by writing an SQL query as follows:

create table LOAN(


loan number int(10) not null,
branch name varchar(30),
amount float(15,2),
check (amount >= 0)
);
Outline Integrity Control Basic Integrity Preservation Problems

Problems

1 Consider the following schema of an online code repository


system like GitHub:
Contributor =
hcontributor name : string , contributor id : integer i
Code-Group = hcontributor id : integer , code group :
string , count submissions : integer i
Set the basic integrity constraints on this schema.

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