Introduction To Relational Databases
Introduction To Relational Databases
Databases
1
What Is a Database?
An organised, machine-readable collection
of symbols, to be interpreted as a true
account of some enterprise.
Machine-updatable, too …
… so a database is also a collection of variables.
2
“Organised Collection of
Symbols”
For example:
StudentId Name CourseId
S1 Anne C1
S1 Anne C2
S2 Boris C1
S3 Cindy C3
4
“Collection of Variables”
ENROLMENT
StudentId Name CourseId
S1 Anne C1
S1 Anne C2
S2 Boris C1
S3 Cindy C3
S4 Devinder C1
8
What Is a DBMS?
A piece of software for managing databases
and providing access to them.
A DBMS responds to imperatives (“statements”)
given by application programs, custom-written
or general-purpose, executing on behalf of users.
Imperatives are written in the database language
of the DBMS (e.g., SQL).
Responses include completion codes, messages and
results of queries.
9
What Does a DBMS Do?
In response to requests given by application programs:
• creates and destroys variables
• takes note of integrity rules (constraints)
• takes note of authorisations (who is allowed to do
what, to what)
• updates variables (honouring constraints and
authorisations)
• provides results of queries
• and more
Now, how does a relational DBMS do these things? …
10
Create and Destroy Variables
Creation (in Tutorial D):
VAR ENROLMENT BASE RELATION
{ StudentId SID ,
Name CHAR,
CourseId CID }
KEY { StudentId, CourseId } ;
Destruction:
11
Take Note of Integrity Rules
E.g., can’t have more than 20,000 enrolments altogether. In
Tutorial D:
CONSTRAINT MAX_ENROLMENTS
COUNT ( ENROLMENT ) <=20000 ;
12
Take Note of Authorisations
E.g. (perhaps – but not in Tutorial D):
PERMISSION U9_ENROLMENT FOR User9
TO READ ENROLMENT ;
13
Updates Variables
E.g.:
DELETE ENROLMENT WHERE StudentId =
SID ( ‘S4’ ) ;
INSERT ENROLMENT
RELATION {
TUPLE { StudentId SID ( ‘S4’ ) ,
Name ‘Devinder’ ,
CourseId CID ( ‘C1’ ) } } ;
14
Provides Results of Queries
E.g.: Who is enrolled on course C1?
(ENROLMENT WHERE CourseId = CID(‘C1’))
{ StudentId, Name }
The result is another relation! In tabular form:
StudentId Name
S1 Anne
S2 Boris
S4 Devinder
15
EXERCISE
Consider this table:
A B A
1 2 3
4 5
6 7 8
9 9 ?
1 2 3
16
IMPORTANT BIT OF ADMIN
Are you:
(a) an overseas student visiting for just one year, or
(b) doing a degree that is completely outside the CS
department? (In which case you should complete an
Unusual Option Form, obtainable from your dept secretary)
Write your name, ITS userid, and course code on the sheet of
paper provided.