3. To build a database using SQL features and relational database
design concepts.
LEARNING OBJECTIVES
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
4. Structure of Relational Model
Attribute Types
Database Schema
Relation Instance
Schema Diagram
Keys
Query Languages
OUTLINE
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
5. Basic Structure of Relational Model
• Relational database consists of a collection of tables
• A row in a table represents a relationship among a set of
values
• Each row is a tuple
• Order in which tuples appear in a relation is irrelevant
5
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
7. Basic Structure - Attribute Types
• The set of allowed values for each attribute is called the
domain of the attribute
• A tuple variable is a variable whose domain is the set of
all tuples.
• If Attribute values are atomic, it is indivisible
• The special value null is a member of every domain.
Indicated that the value is “unknown”
• The null value causes complications atmost needs to be
eliminated
7
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
8. Relation Schema
• Schema of a relation consists of
– attribute definitions
• name
• type/domain
– integrity constraints
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
9. Basic Structure – Relation Schema
• A1, A2, …, An are attributes
• R = (A1, A2, …, An ) is a relation schema
Example:
instructor = (ID, name, dept_name, salary)
• Formally, given sets D1, D2, …. Dn a relation r is a subset of
D1 x D2 x … x Dn
• Relation is a set of n-tuples (a1, a2, …, an) where each ai Di
• Relation – cartesian product of domains
• The current values (relation instance) of a relation are
specified by a table
• An element t of r is a tuple, represented by a row in a table
9
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
10. Basic Structure - Domains
• A1, A2, …, An are attributes
• R = (A1, A2, …, An ) is a relation schema
Example: if relation schema customer is defined
Customer=(customer-name, customer-street, customer-city)
customer-name = {Jones, Smith, Curry, Lindsay}
customer-street = {Main, North, Park}
customer-city = {Harrison, Rye, Pittsfield}
Then r = { (Jones, Main, Harrison),
(Smith, North, Rye),
(Curry, North, Rye),
(Lindsay, Park, Pittsfield)}
is a relation over customer-name x customer-street x
customer-city
10
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
11. RELATION INSTANCE
• The current values (relation instance) of a relation
are specified by a table
• An element t of r is a tuple, represented by a row in
a table
• Order of tuples is irrelevant (tuples may be stored
in an arbitrary order)
Jones
Smith
Curry
Lindsay
customer_name
Main
North
North
Park
customer_street
Harrison
Rye
Rye
Pittsfield
customer_city
customer
attributes
(or columns)
tuples
(or rows)
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
12. Relation Instance
• The current values (relation instance) of a relation are
specified by a table
• An element t of r is a tuple, represented by a row in a
table
• Order of tuples is irrelevant (tuples may be stored in an
arbitrary order)
Jones
Smith
Curry
Lindsay
customer-name
Main
North
North
Park
customer-street
Harrison
Rye
Rye
Pittsfield
customer-city
customer
attributes
tuples
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
13. Relations are Unordered
Example: instructor relation with unordered tuples
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
14. Database Schema
• Database schema – logical design of database
• Database instance - snapshot of the data in the database at
given instant in time.
• Lowercase names for relations
• Names begin with an uppercase letter for relation schemas
Account-schema =(account-number, branch-name, balance)
• Relation schema – consists of list of attributes with
corresponding domains
• account(Account-schema)
14
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
15. Relation instance - notion of a value of a variable and it may
change with time
Attribute branch-name appears in both Branch-schema and
Account schema.
• Branch-schema =(branch-name, branch-city, assets)
• Account-schema =(account-number, branch-name, balance)
Relation schema
• Customer-schema =(customer-name, customer-street,
customer-city, account-number)
Relation between customer and account
• Depositor-schema =(customer-name, account-number)
15
Database Schema Cont..
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
16. Attribute Types
• Each attribute of a relation has a name
• The set of allowed values for each attribute is called the
domain of the attribute
• Attribute values are (normally) required to be atomic, that is,
indivisible
– E.g. multivalued attribute values are not atomic
– E.g. composite attribute values are not atomic
• The special value null is a member of every domain
• The null value causes complications in the definition of many
operations
– we shall ignore the effect of null values in our main
presentation and consider their effect later
16
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
19. E-R Diagram for the Banking Enterprise
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
20. Keys
• Let K R, K is a superkey of R if values for K are sufficient
to identify a unique tuple of each possible relation r(R)
t1 != t2, in relation R
– Example: {account-number},{ branch-name, account-
name} ,{account-name}- superkeys of account
• Superkey K is a candidate key if K is minimal
Example: {account-number} is a candidate key for account
• Foreign key constraint: Value in one relation must appear in
another (ta=tb)
– Referencing relation, Referenced relation
– Example – branch-name in account is a foreign key from
branch referencing account
20
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
21. Determining Keys from E-R Sets
• Strong entity set. The primary key of the entity set
becomes the primary key of the relation.
• Weak entity set. The primary key of the relation
consists of the union of the primary key of the strong
entity set and the discriminator of the weak entity
set.
• Relationship set. The union of the primary keys of the
related entity sets becomes a super key of the
relation.
– For binary many-to-one relationship sets, the primary key of the “many” entity set becomes
the relation’s primary key.
– For one-to-one relationship sets, the relation’s primary key can be that of either entity set.
– For many-to-many relationship sets, the union of the primary keys becomes the relation’s
primary key
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
22. SCHEMA DIAGRAM
22CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
transform it into a normalized relational database schema.
23. Query Languages
• Language in which user requests information from the
database.
• Categories of languages
– procedural
– non-procedural
• “Pure” languages:
– Relational Algebra
– Tuple Relational Calculus
– Domain Relational Calculus
• Pure languages form underlying basis of query
languages that people use.
23
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
24. Summary
RELATIONAL MODEL
• Basic Structure
• Schema-Refers Logical Design
• Keys(Super key, primary key)
• Schema Diagram- Dipiction of schema
• Query Languages
24
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
25. LEARNING OUTCOME
The student will be able to Analyze and derive an information
model expressed in the form of an entity relation diagram and
transform it into Relational Model.
CO2:Analyze and derive an information model expressed in the form of an entity relation diagram and
26. employee (person name, street, city)
works (person name, company name, salary)
company (company name, city)
branch(branch name, branch city, assets)
customer (customer name, customer street, customer city)
loan (loan number, branch name, amount)
borrower (customer name, loan number)
account (account number, branch name, balance)
depositor (customer name, account number)
1. Consider the relational database of Figure ??. What are the
appropriate primary keys?
EXPECTED QUESTIONS
17CS307- DATABASE MANAGEMENT SYSTEMS
27. 1. Describe the differences in meaning between the terms relation
and relation schema.
2. List two reasons why null values might be introduced into the
database.
3. Discuss the relative merits of procedural and nonprocedural
languages.
EXPECTED QUESTIONS
17CS307- DATABASE MANAGEMENT SYSTEMS
28. 28
In the next session, we will discuss about Relational Algebra
17CS307- DATABASE MANAGEMENT SYSTEMS