Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Federal University Gashua

Department of Computer Science

CHAPTER THREE: Relational Database

USMAN SULEIMAN IDRISS


Relational Database Concept
 Dr. E. F. Codd proposed the relational model for
database systems in 1970.

 It is the basis for the RDBMS.

 The relational model consists of the following:


 A collection of objects or relations
 A set of operators to act on the relations
 Data integrity for accuracy and consistency
Relation Database Definition
 A relational database uses relations or two-dimensional
tables to store information.

 Relational databases are organized by fields, records, and


tables.

 A field is a single piece of information; a record is one


complete set of fields; and a table is a collection of records.
Relation Database Definition
Student Table
StudID LastName GPA CourseID
S001 Bartell 3.21 DCS
S003 Lee 3.82 DIT
S005 Law 3.05 DIT
Database S007 Tham 3.89 DCS
S009 Nicosia 3.11 DICT
S010 Owen 3.34 DIC
S015 Chan 3.12 DIC

Course Table
CourseID CourseDesp MentorID
DCS Diploma In Computer Studies 1006
DIC Diploma In Computing 1006
DICT Diploma In Info-Comm Technology 1002
DIT Diploma In Information Technology 1001
Relational Database Terminology
Student table (a)
(c)
StudID LastName FirstName Gender DateEnrolled GPA GroupLeader CourseID
S001 Bartell Joseph P. M 15-Feb-02 3.21 S005 DCS
S002 Kebel Laura N. F 23-Jun-01 2.71 S007 DIC
S003 Lee Choy Yan F 05-Jan-02 3.82 S016 DIT
S004 Lewis Derrick H. M 03-Mar-00 2.51 S007 DICT
S005 Law Arthur M 01-Apr-01 3.05 DIT
(b)
S006 Mikulski Kathleen F 12-Sep-03 1.89 S010 DCS
S007 Tham Tian En F 19-Sep-03 3.89 (e) DCS

S008 Faga Mark J. M 25-Jun-01 2.22 S010 DIC


S009 Nicosia Anthony L. M 01-Feb-02 3.11 S005 DICT
S010 Owen John M. M 17-Sep-01 3.34 DIC

S011 Ng Jian Xian M 01-Apr-01 1.88 S007 DIT


S012 Maser Jennifer L. F 25-Sep-03 3 S016 DICT
S013 Roche Stephanie N. F 30-Mar-00 1.88 S005 DIT
S014 Williams Jason R. M
(d) 12-Dec-02 2.74 S010 DCS
Relational Database Terminology
a. Table
 A relational database system contains one or more objects
called tables.

 The data or information for the database is stored in these


tables.

 Tables are uniquely identified by their names and are


comprised of columns and rows.

 Columns contain the column name, data type, and any other
attributes for the column.

 Rows contain the records or data for the columns. In


relational database, table is also known as relation.
Relational Database Terminology
b. Row
 A single row or tuple representing all data required for a

particular object.

 The Student table (Figure 1.2), shows each row representing a


piece of information about a student.

 Each row in a table should be identified by a primary key,


which allows no duplicate rows.

 The order of rows is insignificant; specify the row order when


the data is retrieved.

 In another words, the rows of a table are considered to be in


no particular order so they are an unordered set.
Relational Database Terminology
C. Column

 A column or attribute contains one particular type of


information that is kept about all the rows in the table.

 A column cannot, or should not, contain one type of


information for one row and another type for another row.
 Each column has a name and it represents it own information.

 For example the StudID column contains a list of student


identification number.

 Column order is insignificant when storing data; specify the


column order when the data is retrieved.

 A column may contain or not contain any key value and also
may served as Primary or Foreign Key.
Relational Database Terminology
Primary key
 A primary key is a single field or combination of fields that

uniquely defines a record.

 None of the fields that are part of the primary key can contain
a null value. A table can have only one primary key.

 The column StudID (as example) is a primary key. This


student number identifies a unique student in the Student
table.

General Guidelines:
 • No duplicate values are allowed in a primary key.

 • Primary keys generally cannot be changed.


Relational Database Terminology
Foreign key
 A foreign key is a field in a relational table that matches the

primary key column of another table.

 The foreign key can be used to cross-reference tables.


 The CourseID column is a foreign key; a column that defines
how tables relate to each other.

 In the example, CourseID uniquely identifies a course in the


Course table.

General Guidelines:
 Foreign keys are based on data values and are purely logical,

not physical, pointers.


 A foreign key value must match an existing primary or unique

key value or be null.


Relating multiple data

Student table Course table


LastNam FirstNam CourseID CourseDesp MentorID
StudID Gender CourseID
e e
DCS Diploma In Computer Studies 1006
S001 Bartell Joseph P. M DCS
DIC Diploma In Computing 1006
S002 Kebel Laura N. F DIC
DICT Diploma In Info-Comm Technology 1002
S003 Lee Choy Yan F DIT
DIT Diploma In Information Technology 1001
S004 Lewis Derrick H. M DICT
S005 Law Arthur M DIT
S006 Mikulski Kathleen F DCS
S007 Tham Tian En F DCS Primary key Foreign key

Primary key Foreign key


Relational Database Terminology
d. Field
 A field can be found at the intersection of a row and a

column.

 There can be only one value in it.

 It is the smallest part of a table and it cannot be broken down


into smaller parts.

 A field contains one single piece of data, a single unit of


information.
Relational Database Terminology
e. Null value
 A field may have no value in it.

 This is called a null value.

 In the Student table, those who are a group leader are not
eligible to be assigning group leader identification to them
because they themselves is a group leader.

 For example S005, the group leader field is with NULL value
because he is not being lead by any leader.
Communicating with a RDBMS by Using SQL.
 Relational database management system or RDBMS in short is
a software or environment that acts as the middleman for the
user to communicate to the database.

 User need to issue the SQL statement at the RDBMS and then
RDBMS will sent this statement to the database and return a
list of result to the user at the RDBMS interface.

 SQL is used to interact with your database's data.

Access uses SQL for many tasks:


 whenever a query is run it uses SQL to filter the data

 whenever a report is displayed SQL is used to gather the data

to be displayed
 SQL provides the data displayed on an Access form
Communicating with a RDBMS by
Using SQL
SQL statement
is entered Statement is sent
to database
SELECT MentorName
FROM Mentor;

Database

Data is displayed
MentorName
Goile
Rimes
Christopher
Schubert
Norman
Carroll
What is SQL?
 SQL (pronounced "sequel") stands for Structured Query
Language.

 SQL is used to communicate with a database.

 According to ANSI (American National Standards Institute), it


is the standard language for relational database management
systems.

 SQL statements are used to perform tasks such as update


data on a database, or retrieve data from a database.
SQL
 Some common relational database management systems that
use SQL are: Oracle, Sybase, Microsoft SQL Server, Access etc.

 Although most database systems use SQL, most of them also


have their own additional proprietary extensions that are
usually only used on their system.

 However, the standard SQL commands such as "Select",


"Insert", "Update", "Delete", "Create", and "Drop" can be used
to accomplish almost everything that one needs to do with a
database.
Data types Supported in Access
Data types Supported in Access
SQL statements
Category SQL statement
Data Retrieval Language (DRL) SELECT

Data Manipulation Language (DML) INSERT


DELETE
UPDATE

Data Definition Language (DDL) CREATE


ALTER
DROP
RENAME
TRUNCATE

Transaction Control COMMIT


ROLLBACK
SAVEPOINT

Data Control Language (DCL) GRANT


REVOKE
Tables used in the Course
Four main tables are used in this course:
◦ Student table
◦ Course table
◦ Mentor table
◦ GradeTable table
Student table
StudID LastName FirstName Gender DateEnrolled GPA GroupLeader CourseID
S001 Bartell Joseph P. M 15-Feb-02 3.21 S005 DCS
S002 Kebel Laura N. F 23-Jun-01 2.71 S007 DIC
S003 Lee Choy Yan F 05-Jan-02 3.82 S016 DIT
S004 Lewis Derrick H. M 03-Mar-00 2.51 S007 DICT
S005 Law Arthur M 01-Apr-01 3.05 DIT
S006 Mikulski Kathleen F 12-Sep-03 1.89 S010 DCS
S007 Tham Tian En F 19-Sep-03 3.89 DCS
S008 Faga Mark J. M 25-Jun-01 2.22 S010 DIC
S009 Nicosia Anthony L. M 01-Feb-02 3.11 S005 DICT
S010 Owen John M. M 17-Sep-01 3.34 DIC
S011 Ng Jian Xian M 01-Apr-01 1.88 S007 DIT
S012 Maser Jennifer L. F 25-Sep-03 3 S016 DICT
S013 Roche Stephanie N. F 30-Mar-00 1.88 S005 DIT
S014 Williams Jason R. M 12-Dec-02 2.74 S010 DCS

Primary key Foreign key Foreign key


Course Table
CourseID CourseDesp MentorID
DCS Diploma In Computer Studies 1006
DGAT Diploma in Gaming and Animation Techniques 1004
DIC Diploma In Computing 1006
DICT Diploma In Info-Comm Technology 1002
DIT Diploma In Information Technology 1001
DNC Diploma in Network and CyberSecurity 1003

Primary key Foreign key


Mentor and GradeTable table
MentorID MentorName Grade Hi_gradepoint Low_gradepoint
1001 Goile A 4 4
1002 Rimes B 3.9 3
1003 Christopher C 2.9 2
1004 Schubert D 1.9 1
1005 Norman F 0.9 0
1006 Carroll

Primary key
Primary key
 END

 ANY QUESTION?

You might also like