Download presentation
Presentation is loading. Please wait.
Published byCharity Moody Modified over 8 years ago
1
Chapter 3 The Relational Model
2
Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy systems” in older models E.G., IBM’s IMS Recent competitor: object-oriented model ObjectStore, Versant, Ontos A synthesis emerging: object-relational model Informix Universal Server, UniSQL, O2, Oracle, DB2
3
Relational Model The Relational Model is very simple and elegant: a database is a collection of one or more relations, where each relation is a table with rows and columns. The major advantages of the relational model over the older data models are its simple data representation and the ease with which even complex queries can be expressed.
4
Relational Model The DDL(Data Definition Language) features of SQL, the standard language for creating, manipulating, and querying data in a relational DBMS. An important component of a data model is the set of constructs it provides for specifying conditions that must be satisfied by the data. Such conditions called integrity constraints(ICs) enable the DBMS to reject operations that might corrupt the data.
5
Relational Database Relational database: a set of relations Relation: made up of 2 parts: Instance : a table, with rows and columns. #Rows = cardinality, #fields = degree / arity. Schema : specifies name of relation, plus name and type of each column. E.G. Students(sid: string, name: string, login: string, age: integer, gpa: real).
6
Relational Database A domain is referred to in a relation schema by the domain name and has a set of associated values. In above example the field name sid has a domain named string. The set of values associated with domain string is the set of all character strings. An instance of a relation is a set of tuples, also called records in which each tuple has the same number of fields as the relation schema.
7
Relational Database The requirement of relational model is each relation is defined to be a set of unique tuples or rows. A relation schema specifies the domain of each field or column in the relation instance. These domain constraints in the schema specify an important condition that we want each instance of the relation to satisfy. The values that appear in a column must be drawn from the domain associated with that column.
8
Relational Database More formally let R(f1:D1….Fn:Dn) be a relation schema and for each Fi, 1<=i<=n, let Dom(i) be the set of values associated with the domain named Di. Domain constraints are so fundamental in the relational model that we henceforth consider only relation instances that satisfy them; therefore, relation instance means relation instance that satisfies the domain constraints in the relation schema.
9
Relational Database The degree also called arity, of a relation is the number of fields. The cardinality of a relation instance is the number of tuples in it. vCardinality = 3, degree = 5, all rows distinct
10
Relational Database A relational database is a collection of relations with distinct relation names. The relational database schema is the collection of schemas for the relations in the database. An instance of a relational database is a collection of relation instances, one per relation schema in the database schema; of course each relation instance must satisfy the domain constraints in its schema.
11
Relational Query Languages A major strength of the relational model: supports simple, powerful querying of data. Queries can be written intuitively, and the DBMS is responsible for efficient evaluation. The key: precise semantics for relational queries. Allows the optimizer to extensively re-order operations, and still ensure that the answer does not change.
12
The SQL Query Language To find all 18 year old students, we can write: SELECT * FROM Students S WHERE S.age=18 To find just names and logins, replace the first line: SELECT S.name, S.login
13
Querying Multiple Relations What does the following query compute? SELECT S.name, E.cid FROM Students S, Enrolled E WHERE S.sid=E.sid AND E.grade=“A” Given the following instance of Enrolled (is this possible if the DBMS ensures referential integrity?): we get:
14
Creating Relations in SQL Creates the Students relation. Observe that the type (domain) of each field is specified, and enforced by the DBMS whenever tuples are added or modified. As another example, the Enrolled table holds information about courses that students take. CREATE TABLE Students (sid CHAR(20), name CHAR(20), login CHAR(10), age INTEGER, gpa REAL ) CREATE TABLE Enrolled (sid CHAR(20), cid CHAR(20), grade CHAR (2))
15
Destroying and Altering Relations Destroys the relation Students. The schema information and the tuples are deleted. DROP TABLE Students v The schema of Students is altered by adding a new field; every tuple in the current instance is extended with a null value in the new field. ALTER TABLE Students ADD COLUMN firstYear: integer
16
Adding and Deleting Tuples Can insert a single tuple using: INSERT INTO Students (sid, name, login, age, gpa) VALUES (53688, ‘Smith’, ‘smith@ee’, 18, 3.2) v Can delete all tuples satisfying some condition (e.g., name = Smith): DELETE FROM Students S WHERE S.name = ‘Smith’ * Powerful variants of these commands are available; more later!
17
Relational Model: Summary A tabular representation of data. Simple and intuitive, currently the most widely used. Integrity constraints can be specified by the DBA, based on application semantics. DBMS checks for violations. Two important ICs: primary and foreign keys In addition, we always have domain constraints. Powerful and natural query languages exist. Rules to translate ER to relational model
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.