You are on page 1of 24

(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.
back

(b)

Row

A single

row or tuple representing all data


required for a particular object.
The Student table 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.
The rows of a table are considered to be in no
particular order so they are an unordered set.
back

(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.

back

(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.
back

(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.
back

Chapter 1
Introduction to Relational
Database and SQL

CS165 Structured Query Language

Objectives
The

differences between database and


relational database
Concept and definition on relational
database
Common terminology used in relational
database
Basic concept of SQL

What is Database ?
A database
is

a collection of related data organized in a


manner that allows access, retrieval, use, and
maintenance of that data.

Database

Management System (DBMS)

A software

that allows to manipulate the data


store in the database.

Benefits of Database
Data

Independence
Data Consistency
Controlled Redundancy
Data Integrity
Data

Security

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

Database

StudID
S001
S003
S005
S007
S009
S010
S015

LastName
Bartell
Lee
Law
Tham
Nicosia
Owen
Chan

GPA
3.21
3.82
3.05
3.89
3.11
3.34
3.12

CourseID
DCS
DIT
DIT
DCS
DICT
DIC
DIC

Course Table
CourseID
DCS
DIC
DICT
DIT

CourseDesp
MentorID
Diploma In Computer Studies
1006
Diploma In Computing
1006
Diploma In Info-Comm Technology 1002
Diploma In Information Technology 1001

Relational Database Terminology


Student table (a)
(c)
StudID

LastName

FirstName

Gender

GroupLeader

CourseID

S001

Bartell

Joseph P.

15-Feb-02

3.21

S005

DCS

S002

Kebel

Laura N.

23-Jun-01

2.71

S007

DIC

S003

Lee

Choy Yan

05-Jan-02

3.82

S016

DIT

S004

Lewis

Derrick H.

03-Mar-00

2.51

S007

DICT

S005

Law

Arthur

01-Apr-01

3.05

S006

Mikulski

Kathleen

12-Sep-03

1.89

S007

Tham

Tian En

19-Sep-03

3.89

S008

Faga

Mark J.

25-Jun-01

2.22

S010

DIC

S009

Nicosia

Anthony L.

01-Feb-02

3.11

S005

DICT

S010

Owen

John M.

17-Sep-01

3.34

S011

Ng

Jian Xian

01-Apr-01

1.88

S007

DIT

S012

Maser

Jennifer L.

25-Sep-03

S016

DICT

S013

Roche

Stephanie N.

30-Mar-00

1.88

S005

DIT

S014

Williams

Jason R.

12-Dec-02

2.74

S010

DCS

(d)

DateEnrolled

GPA

DIT
S010

(e)

DCS
DCS

DIC

(b)

Primary Key vs Foreign Key


Primary key
A primary

key is a single field or combination of fields


that uniquely defines a record.
Cannot contain a null value.
A table can have only one primary key.
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.

Relating multiple data


Course table

Student table
StudID

LastName

FirstName

Gender

CourseID

S001

Bartell

Joseph P.

DCS

DCS

Diploma In Computer Studies

1006

S002

Kebel

Laura N.

DIC

DIC

Diploma In Computing

1006

S003

Lee

Choy Yan

DIT

DICT

Diploma In Info-Comm Technology

1002

S004

Lewis

Derrick H.

DICT

DIT

Diploma In Information Technology

1001

S005

Law

Arthur

DIT

S006

Mikulski

Kathleen

DCS

S007

Tham

Tian En

DCS

Primary key

Foreign key

CourseID

CourseDesp

Primary key

MentorID

Foreign key

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.

Data types Supported in Access


Text
Memo
Number
Date/Time
Currency
AutoNumber
Yes/No
OLE

object
Hyperlink

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

StudID

LastName

Student table

FirstName

Gender

DateEnrolled

GPA

GroupLeader

CourseID

S001

Bartell

Joseph P.

15-Feb-02

3.21

S005

DCS

S002

Kebel

Laura N.

23-Jun-01

2.71

S007

DIC

S003

Lee

Choy Yan

05-Jan-02

3.82

S016

DIT

S004

Lewis

Derrick H.

03-Mar-00

2.51

S007

DICT

S005

Law

Arthur

01-Apr-01

3.05

S006

Mikulski

Kathleen

12-Sep-03

1.89

S007

Tham

Tian En

19-Sep-03

3.89

S008

Faga

Mark J.

25-Jun-01

2.22

S010

DIC

S009

Nicosia

Anthony L.

01-Feb-02

3.11

S005

DICT

S010

Owen

John M.

17-Sep-01

3.34

S011

Ng

Jian Xian

01-Apr-01

1.88

S007

DIT

S012

Maser

Jennifer L.

25-Sep-03

S016

DICT

S013

Roche

Stephanie N.

30-Mar-00

1.88

S005

DIT

S014

Williams

Jason R.

12-Dec-02

2.74

S010

DCS

Primary key

DIT
S010

DCS
DCS

DIC

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

1002

Rimes

3.9

1003

Christopher

2.9

1004

Schubert

1.9

1005

Norman

0.9

1006

Carroll

Primary key

Primary key

Summary
Discussed

the meaning of database and


its benefits.
Focus on relation database and also to
understand the terminology being used.
Additionally, we also discussed SQL as a
language to get information from relational
databases.

You might also like