Professional Documents
Culture Documents
Lec2 - Introduction To The Relational Model (2D Table)
Lec2 - Introduction To The Relational Model (2D Table)
Lec2 - Introduction To The Relational Model (2D Table)
programming
Lecture 2: Introduction to the relational model
(2D table)
By: Dr. Ahmad Barghash
Where to
start?
What is a data model
• A structure of data:
• Similar to structs in C language.
• Data structures are frequently labelled as the physical model. However, the actual
physical model is at the hardware side.
• With data operations:
• Using programming.
• Queries and modifications.
• Wide set of algorithms such as search algorithms.
• And constraints on the data
• Data type constraints (int char,..).
Working with structures
• Structures are tools used for grouping elements and storing data.
• The data is grouped under one name but still the individual entities can be reached using the dot (.)
• All you need is definition, declaration, then accessing .
#include <stdio.h>
struct time timeUpdate (struct time now);
struct time
{
int hour;
int minutes;
int seconds;
};
• Today, the two data models of preeminent importance for database systems are:
1. The relational model, including object-relational extensions.
2. The semistructured-data model, including XML and related standards.
• The first, which is present in all commercial database management systems, is the
subject of this chapter. The semistructured model, of which XML is the primary
manifestation, is an added feature of most relational DBMS’s, and appears in a
number of other contexts as well.
The Relational Model
• The relational model is based on tables.
• This relation, or table, describes movies: their title, the year in which they were made, their
length in minutes, and the genre of the movie.
• The structure portion of the relational model might appear to resemble an array of structs in C.
Array of structures
struct time
{
int hour;
int minutes;
int seconds;
};
.
.
.
struct time timeUpdate (struct time now);
struct time testTimes[5] = { { 11, 59, 59 }, { 12, 0, 0 }, { 1, 29, 59 }, { 23, 59, 59 }, { 19, 12, 27 }};
What is the output of this program slide1
#include <stdio.h>
struct time
{
int hour;
int minutes;
int seconds;
};
int main (void)
{
struct time testTimes[5] =
{ { 11, 59, 59 }, { 12, 0, 0 }, { 1, 29, 59 },
{ 23, 59, 59 }, { 19, 12, 27 }};
int i;
for ( i = 0; i < 5; ++i )
{
printf ("Time is %.2i:%.2i:%.2i", testTimes[i].hour,testTimes[i].minutes, testTimes[i].seconds);
testTimes[i] = timeUpdate (testTimes[i]);
printf (" ...one second later it's %.2i:%.2i:%.2i\n",testTimes[i].hour, testTimes[i].minutes, testTimes[i].seconds);
}
return 0;
}
What is the output of this program slide2
struct time timeUpdate (struct time now)
{
++now.seconds;
if ( now.seconds == 60 ) The output is:
{ // next minute Time is 11:59:59 ...one second later it's 12:00:00
now.seconds = 0; Time is 12:00:00 ...one second later it's 12:00:01
++now.minutes; Time is 01:29:59 ...one second later it's 01:30:00
if ( now.minutes == 60 ) Time is 23:59:59 ...one second later it's 00:00:00
{ // next hour Time is 19:12:27 ...one second later it's 19:12:28
now.minutes = 0;
++now.hour;
if ( now.hour == 24 )
now.hour = 0;
}
}
return now;
}
The semi-structured model
XML data?
</Movie>
<Movie title="Star Wars">
<Year>1977</Year>
<Length>124</Length>
<Genre>sciFi</Genre>
</Movie>
<Movie title="Wayne’s World">
<Year>1992</Year>
<Length>95</Length>
<Genre> comedy</Genre>
</Movie>
</Movies>
Why the Provides a simple, limited approach to structuring
data, yet is reasonably versatile, so anything can be
relational modeled.
model is
widely
Provides a limited, yet useful, collection of
accepted operations on data.
• The relational model requires that each component of each tuple be of some elementary type such
as integer or string. It can not be a a record structure, set, list, array, or any other type that
reasonably can have its values broken into smaller components.
• In the relational model, a database consists of one or more relations.
• The set of schemas for the relations of a database is called a Relational database schema, or just a
database schema.
• Follow the convention that relation names begin with a capital letter, and attribute names begin
with a lower-case letter.
• Ordering the relations by a specific attribute generates an acceptable equivalent view of the
database.
Full schema can look like
Lets test our
knowledge
Indicate the following:
a) The attributes of each relation.
b) The tuples of each relation.
c) The components of one tuple from each
relation.
d) The database schema.
e) A suitable domain for each attribute.
f) Another equivalent way to present each
relation…..And how many can we get?
g) Give examples about possible keys.