7th relational data model.pptx
TRANSCRIPT
Relational Model
• First introduced in 1970 by E.F. Codd at IBM.
• Two early research projects on relational model:
• IBM System R (prototype RDBMS)• UC Berkeley’s Ingres (academic RDBMS)
A tabular representation of data.A major strength of the relational model:
supports simple, powerful querying of data.
Relational Model
• Relational model -basic concepts
• Enforcing Data Integrity Constraints
• Structure of Relational Databases
• Fundamental Relational-Algebra-Operations
• Extended Relational-Algebra-Operations
• Null Values
• Modification of the Database
• Relational Calculus
• Assertion and Triggers
• Introduction on views
• Codd's Rules
Domains, Attributes, Tuples and Relations:
• Relational database: a set of relations.
• Relation: made up of two parts:• Instance : a table, with rows and columns.
#Rows = cardinality, #fields = degree / arity.• Schema : Description of data at some abstraction
level which specifies name of relation, plus name and type of each column.
• Students (sid: string, name: string,
login: string, age: integer,
gpa: real )
Example of a Relation
sid name login age gpa
53666 Jones jones@cs 18 3.4
53688 Smith smith@eecs 18 3.2
53650 Smith smith@math 19 3.8
oCan think of a relation as a set of rows or tuples (i.e., all rows are distinct).
oDo all columns in a relation instance have to be distinct?
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. the value of an attribute can be an account
number, but cannot be a set of account numbers.
Domain is said to be atomic if all its members are atomic
The special value null is a member of every domain but null value causes complications in the definition of many operations.
Relation Schema:
Schema of a relation consists of• Attribute definitions • name• type/domain
Integrity constraints: Restriction on state (or of sequence of states) of a database
• The values of a particular attribute in all tuples are unique (structural).• The values of a particular attribute in all
tuples are greater than zero (Sementic).
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)
JonesSmithCurryLindsay
customer_name
MainNorthNorthPark
customer_street
HarrisonRyeRyePittsfield
customer_city
customer
attributes(or columns)
tuples(or rows)
Database:
• A database consists of multiple relations
• Information about an enterprise is broken up into parts, with each relation storing one part of the information
• E.g.
account : information about accounts depositor : which customer owns which account customer : information about customers
Why Split Information AcrossRelations?
• Storing all information as a single relation such as bank (account_number, balance, customer_name, ..)results in
• Repetition of information
• e.g.,if two customers own an account
• The need for null values
• e.g., to represent a customer without an account
• Normalization theory deals with how to design relational schemas.
Integrity constraints
• IC: condition that must be true for any instance of the database; e.g., domain constraints.• ICs are specified when schema is defined.• ICs are checked when relations are modified.
• A legal instance of a relation is one that satisfies all specified ICs. • DBMS should not allow illegal instances.
• Avoids data entry errors, too.
• Automatically checked by DBMS.
• Enforces enterprise rules.
Key constraint
• A relation instance s of S (relational schema)
satisfies the key constraint iff at most one row in s can contain a particular set of values, a1,…,an, for the attributes A1,…,An (sequence of attributes ).
• Key• Set of attributes mentioned in a key constraint
• e.g., Id in Student relation.
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)
• In real life, an attribute such as customer_id would be used instead of customer_name to uniquely identify customers.
Keys (Cont.)
• K is a candidate key if K is minimalExample: {customer_name} is a candidate key for Customer, since it is a superkey and no subset of it is a superkey.
• Primary key: a candidate key chosen as the principal means of identifying tuples within a relation
• Should choose an attribute whose value never, or very rarely, changes.
• E.g. email address is unique, but may change.
• Possibly many candidate keys, one of which is chosen as the primary key.
Foreign Keys
• A relation schema may have an attribute that corresponds to the primary key of another relation. The attribute is called a foreign key.
• E.g. customer_name and account_number attributes of depositor are foreign keys to customer and account respectively.
• Only values occurring in the primary key attribute of the referenced relation may occur in the foreign key attribute of the referencing relation.
Example:
sid name login age gpa
53666 Jones jones@cs 18 3.453688 Smith smith@eecs 18 3.253650 Smith smith@math 19 3.8
sid cid grade53666 Carnatic101 C53666 Reggae203 B53650 Topology112 A53666 History105 B
Stud_
Views:
• A view is just a relation, but we store a definition, rather than a set of tuples.
CREATE VIEW YoungActiveStudents (name, grade)AS SELECT S.name, E.gradeFROM Students S, Enrolled EWHERE S.sid = E.sid and S.age<21
Query Languages
• Language in which user requests information from the database.
• Categories of languages• Procedural• Non-procedural, or declarative
• “Pure” languages:• Relational algebra• Tuple relational calculus• Domain relational calculus
• Pure languages form underlying basis of query languages that people use.