Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Relational database
1. Unit II
• Introduction to Relational
Database – Relational
Database terms: Records –
Fields Tables – Advantage and
disadvantage of Relational
Database.
3. Relational Database
• The 'Relational Database Model is the most
common model in industry today.
• A relational database is based on the relational
model developed by E.F. Codd.
• A relational database allows the definition of data
structures, storage and retrieval operations and
integrity constraints.
• In relational database the data and relations
between them are organized into tables. A table
is a collection of records and each record in a
table contains the same fields.
4. Database terms
A database is a collection of data
Data is organised into one or more tables
Each row is a record
Each column is a field
Name Role Town
record 1 Peter farmer Oxford
record 2 Mary weaver Winch
record 3 Seth drover Bristol
5. Relational model
Data are organized in two-dimensional tables called
relations.
The tables are related to each other.
The most popular model.
6. Relation
Name – each relation in a relational database should have a name that is
unique among other relations.
Attribute – each column in a relation.
The degree of the relation – the total number of attributes for a relation.
Tuple – each row in a relation.
The cardinality of the relation – the total number of rows in a relation.
Tables Relation
Rows Tuples
Columns Attributes
7. To Design Relational Database
• Decide on the fields
• Think of all the facts that will be collected
• plenty of fields
• consult widely
• small facts, “atomic”
8. Designing the tables
Plan it on paper first
Choose the fields, then group them in tables
9. Designing the tables
People
Surname Wilson Temple Sterling Elliott
First name Adam Thos Oliver Justin
Middle initial(s) T G J K W
Date of birth 3/8/1697 6/10/1705 23/5/1720 24/2/1718
…
Place Born France London landowner
10. Types of data
Set a data type
for each field:
Text, Number,
Date/time,
Currency, Yes/No
People
Surname text
First name text
Middle initial(s) text
Date of birth date
…
Mobile No Number
Books
Title text
Author text
DatePub date
…
Place text
ISBN text
…
…
11. An example scenario
And what information might we want to know about
each of these things?
Names
Dates
Places
Where we got the information from
12. Person
Surname
First name
Middle initial(s)
Date of birth
Notes
Publication
Title
Author(s)
Publisher
Date of publication
Place of publication
Edition
Format
Type of publication
Price
Sales
Notes
Publisher
Name
Staff
Founded
Ceased
Address
Notes
Reference
Author(s)
Title
Date of publication
Edition
Volume
Page(s)
URL
Notes
13. Primary key
Each table needs a primary key
Choose (at least) one field that only contains
unique values
Commonly an auto-incrementing whole (integer) number
14. Person
PersonID
Surname
First name
Middle initial(s)
Date of birth
Notes
Publication
PubnID
Title
Author(s)
Publisher
Date of publication
Place of publication
Edition
Format
Type of publication
Price
Sales
Notes
Publisher
PublisherID
Name
Staff
Founded
Ceased
Address
Notes
Reference
ReferenceID
Author(s)
Title
Date of publication
Edition
Volume
Page(s)
URL
Notes
15. Relating two tables - joins
Mark the field that links this table to that table
Draw join lines
Convenient to have same or similar field names
16. Publication
PubnID
Title
Author
Publisher
Date of publication
Place of publication
Edition
Format
Type of publication
Price
Reference
PageInReference
Publisher
PublisherID
Name
Staff
Founded
Ceased
Address
Reference
PageInReference
Reference
ReferenceID
Author(s)
Title
Date of publication
Edition
Volume
Page(s)
URL
Notes
Person
PersonID
Surname
First name
Middle initial(s)
Date of birth
Notes
Reference
∞
PageInReference
1
∞
1
∞
∞
8 July,
2016
Page 16
Digital Humanities Summer School-
An Introduction to RelationalDatabases
17. Publication
PubnID
Title
Author(s)
Publisher
Date of publication
Place of publication
Edition
Format
Type of publication
Price
Reference
PageInReference
∞
1
1
Person
PersonID
Surname
First name
Middle initial(s)
Date of birth
Notes
Reference
PageInReference
Publisher
PublisherID
Name
Staff
Founded
Ceased
Address
Reference
PageInReference
Reference
ReferenceID
Author(s)
Title
Date of publication
Edition
Volume
Page(s)
URL
Notes
1
∞
1
∞
∞
∞
Authorship
ID
Author
Publication
∞
8 July,
2016
Page 17
Digital Humanities Summer School-
An Introduction to RelationalDatabases
18. Publication
Int
Title Text
Publisher INT
Date of
publication
Int?
Place of
publication
Text
Edition Int
Format Text
Type
publi
of Text
Price
cation
Dec?
Int?
Reference Int
Page Text
Notes Text
8 July, 2016
Page 36
on
Publisher
Int
Name Text
Founded Int?
Ceased Int?
Address Text
Reference Int
ageP
Notes Text
Reference
ID Int
Title Text
Date of
publication
Int?
Edition Int?
Volume Int?
URL Text
Notes Text
1 ID
∞
1
∞
Text∞
∞
Publisher_Staff
ID Int
Publisher
Sales
Int
Int
Reference_Author
ID Int
Reference Int
Int
∞
?
∞
Authorship
ID Int
Author Int
Publication Int
Per s
1
AuthorID Int
Surname Text
First name Text
Middle
initial(s)
Text
Date of birth Date
Reference Int
Page Text
Notes Text
1 ID
∞Staff_Member
∞
∞
∞Reference_Author
19. Properties of the Relational database
model
Properties of Relational Tables:
• 1. Data is presented as a collection of
relations.
• 2. Each relation is depicted as a table.
• 3. Columns are attributes that belong to the
entity modeled by the table (ex. In a student
table, you could have name, address, student
ID, major, etc.).
20. Properties of the Relational database
model
• 4. Each row ("tuple") represents a single entity
(ex. In a student table, John Smith, 14 Oak
St,9002342, Accounting, would represent one
student entity).
• 5. Every table has a set of attributes that taken
together as a "key" (technically, a "superkey")
uniquely identifies each entity (Ex. In the student
table, “student ID” would uniquely identify each
student – no two students would have the same
student ID).
22. Operations on relations
• In a relational database, we can define several operations to
create new relations out of the existing ones.
• Basic operations:
– Insert
– Delete
– Update
– Select
– Project
– Join
– Union
– Intersection
– Difference
24. Delete operation
An unary operation.
Delete a tuple defined by a criterion from the relation.
25. Update operation
An unary operation.
Changes the value of some attributes of a tuple.
26. Select operation
An unary operation.
It is applied to one single relation and creates another relation.
The tuples in the resulting relation are a subset of the tuples in
the original relation.
Use some criteria to select
27. Project operation
An unary operation.
It is applied to one single relation and creates another relation.
The attributes in the resulting relation are a subset of the
attributes in the original relation.
28. Join operation
A binary operation.
Combines two relations based on common attributes.
29. Union operation
A binary operation.
Creates a new relation in which each tuple is either in the first
relation, in the second, or in both.
The two relations must have the same attributes.
30. Intersection operation
A binary operation.
Creates a new relation in which each tuple is a member in both
relations.
The two relations must have the same attributes.
31. Difference operation
A binary operation.
Creates a new relation in which each tuple is in the first relation
but not the second.
The two relations must have the same attributes.