4-M2_ Relational Database Design using ER-to-Relational Mapping-21-01-2025
This document provides an overview of the relational data model, introduced by Ted Codd in 1970, which uses mathematical relations as its foundational concept. It details the structure of relations, including tuples, attributes, and domains, as well as the constraints that govern database states, such as entity integrity and referential integrity. The document also discusses operations within the relational model, including data retrieval and updates, and the implications of deletion operations on relational integrity.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views22 pages
4-M2_ Relational Database Design using ER-to-Relational Mapping-21-01-2025
This document provides an overview of the relational data model, introduced by Ted Codd in 1970, which uses mathematical relations as its foundational concept. It details the structure of relations, including tuples, attributes, and domains, as well as the constraints that govern database states, such as entity integrity and referential integrity. The document also discusses operations within the relational model, including data retrieval and updates, and the implications of deletion operations on relational integrity.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22
Database Management System
Module 3- Chapter 5
The Relational Data Model and Relational
Database Constraints Sandipan Maiti CSE Department [email protected]; 9440412576 Relational Data Model • The relational data model was first introduced by Ted Codd of IBM Research in 1970 in a classic paper (Codd, 1970). • It attracted immediate attention due to its simplicity and mathematical foundation. • The model uses the concept of a mathematical relation—which looks somewhat like a table of values—as its basic building block, and has its theoretical basis in set theory and first-order predicate logic. Relational Model Concepts • The relational model represents the database as a collection of relations. • Informally, each relation resembles a table of values or, to some extent, a flat file of records. • It is called a flat file because each record has a simple linear or flat structure. • When a relation is thought of as a table of values, each row in the table represents a collection of related data values. • A row represents a fact that typically corresponds to a real-world entity or relationship. • The table name and column names are used to help to interpret the meaning of the values in each row. Databases • A database that stores student and course information. Relational Data Model • In the formal relational model terminology, a row is called a tuple, • a column header is called an attribute, • the table is called a relation. • The data type describing the types of values that can appear in each column is represented by a domain of possible values. • A domain D is a set of atomic values. • Atomic mean that each value in the domain is indivisible as far as the formal relational model is concerned. • A common method of specifying a domain is to specify a data type from which the data values forming the domain are drawn. • Usa_phone_numbers: The set of ten-digit phone numbers valid in the United States • Social_security_numbers. The set of valid nine-digit Social Security numbers. Relational Data Model • A relation schema R, denoted by R(A1, A2, … , An), is made up of a relation name R and a list of attributes, A1, A2, … , An. • Each attribute Ai is the name of a role played by some domain D in the relation schema R. • D is called the domain of Ai and is denoted by dom(Ai). • A relation schema is used to describe a relation; R is called the name of this relation. • The degree (or arity) of a relation is the number of attributes n of its relation schema. • A relation of degree seven, stores students information, contain seven attributes for each student: • STUDENT(Name, Ssn, Home_phone, Address, Office_phone, Age, Gpa) • Using the data type of each attribute: • STUDENT(Name: string, Ssn: string, Home_phone: string, Address: string, Office_phone: string, Age: integer, Gpa: real) Relational Data Model • A relation (or relation state) r of the relation schema R(A1, A2, … , An), also denoted by r(R), is a set of n-tuples r = {t1, t2, … , tm}. • Each n-tuple t is an ordered list of n values t =<v1, v2, … , vn>, where each value vi, 1 ≤ i ≤ n, is an element of dom (Ai) or is a special NULL value. (vi=dom(Ai)) • The terms relation intension for the schema R and relation extension for a relation state r(R) are also commonly used. Relational Data Model • The earlier definition of a relation can be restated more formally using set theory concepts as follows. • A relation (or relation state) r(R) is a mathematical relation of degree n on the domains dom(A1), dom(A2), … , dom(An), which is a subset of the Cartesian product (denoted by ×) of the domains that define R:
• The Cartesian product specifies all possible combinations of values from
the underlying domains. Hence, if we denote the total number of values, or cardinality, in a domain D by |D| Relational Data Model • Of all these possible combinations, a relation state at a given time—the current relation state—reflects only the valid tuples that represent a particular state of the real world. • It is possible for several attributes to have the same domain. The attribute names indicate different roles, or interpretations, for the domain. • Ordering of Tuples in a Relation. A relation is defined as a set of tuples. Mathematically, elements of a set have no order among them; hence, tuples in a relation do not have any particular order. • Tuple ordering is not part of a relation definition because a relation attempts to represent facts at a logical or abstract level. Relational Data Model
• According to this definition of tuple as a mapping, a tuple can be
considered as a set of (<attribute>, <value>) pairs, Relational Data Model • When the attribute name and value are included together in a tuple, it is known as self-describing data, because the description of each value (attribute name) is included in the tuple. • Each value in a tuple is an atomic value; that is, it is not divisible into components within the framework of the basic relational model. • Hence, composite and multivalued attributes are not allowed. • This model is sometimes called the flat relational model. • This is called the first normal form assumption. • In general, we can have several meanings for NULL values, such as value unknown, value exists but is not available, or attribute does not apply to this tuple (also known as value undefined). Relational Data Model • Relational Model Notation: • A relation schema R of degree n is denoted by R(A1, A2, … , An). • The uppercase letters Q, R, S denote relation names • The lowercase letters q, r, s denote relation states. • The letters t, u, v denote tuples. • the name of a relation schema such as STUDENT also indicates the current set of tuples in that relation—the current relation state. • An attribute A can be qualified with the relation name R to which it belongs by using the dot notation R.A—for example, STUDENT.Name or STUDENT.Age. • An n-tuple t in a relation r(R) is denoted by t = <v1, v2, … , vn>, where vi is the value corresponding to attribute Ai. Relational Data Model Constraints • The state of the whole database will correspond to the states of all its relations at a particular point in time. • There are generally many restrictions or constraints on the actual values in a database state. • 1. Constraints that are inherent in the data model. We call these inherent model-based constraints or implicit constraints. • 2. Constraints that can be directly expressed in the schemas of the data model, typically by specifying them in the DDL. We call these schema- based constraints or explicit constraints. • 3. Constraints that cannot be directly expressed in the schemas of the data model and hence must be expressed and enforced by the application programs or in some other way. We call these application-based or semantic constraints or business rules. Relational Data Model Constraints • The constraint that a relation cannot have duplicate tuples is an inherent constraint. • Another important category of constraints is data dependencies, which include functional dependencies and multivalued dependencies. They are used mainly for testing the “goodness” of the design of a relational database and are utilized in a process called normalization. • a relation is defined as a set of tuples. • All elements of a set are distinct; hence, all tuples in a relation must also be distinct. • we denote one subset of attributes by SK; then for any two distinct tuples t1 and t2 in a relation state r of R, t1[SK] ≠ t2[SK] such set of attributes SK is called a superkey of the relation schema R . Relational Data Model Constraints • Every relation has at least one default superkey— the set of all its attributes. • A key k of a relation schema R is a superkey of R with the additional property that removing any attribute A from K leaves a set of attributes K′ that is not a superkey of R any more. • This uniqueness property also applies to a superkey. • minimal superkey—that is, a superkey from which we cannot remove any attributes and still have the uniqueness constraint hold. • A relation schema may have more than one key. In this case, each of the keys is called a candidate key. • It is common to designate one of the candidate keys as the primary key of the relation. Relational Data Model • The choice of one to become the primary key is somewhat arbitrary; • It is usually better to choose a primary key with a single attribute or a small number of attributes. • The other candidate keys are designated as unique keys. • A relational database schema S is a set of relation schemas S = {R1, R2, … , Rm} and a set of integrity constraints IC. • A relational database state DB of S is a set of relation states DB = {r1, r2, … , rm} such that each ri is a state of Ri and such that the ri relation states satisfy the integrity constraints specified in IC. • A database state that does not obey all the integrity constraints is called not valid, and a state that satisfies all the constraints in the defined set of integrity constraints IC is called a valid state. Relational Data Model • The entity integrity constraint states that no primary key value can be NULL. • The referential integrity constraint is specified between two relations and is used to maintain the consistency among tuples in the two relations. • A set of attributes FK in relation schema R1 is a foreign key of R1 that references relation R2 if it satisfies the following rules: • 1. The attributes in FK have the same domain(s) as the primary key attributes PK of R2; the attributes FK are said to reference or refer to the relation R2. • 2. A value of FK in a tuple t1 of the current state r1(R1) either occurs as a value of PK for some tuple t2 in the current state r2(R2) or is NULL. In the former case, we have t1[FK] = t2[PK], and we say that the tuple t1 references or refers to the tuple t2 Relational Data Model • R1 is called the referencing relation and R2 is the referenced relation. • If these two conditions hold, a referential integrity constraint from R1 to R2 is said to hold. Relational Data Model • The operations of the relational model can be categorized into retrievals and updates. • The user formulates a query that specifies the data of interest, and a new relation is formed by applying relational operators to retrieve this data. The result relation becomes the answer to (or result of ) the user’s query. • Three basic operations can change the states of relations in the database: Insert, Delete, and Update (or Modify). • They insert new data, delete old data, or modify existing data records, respectively. Insert is used to insert one or more new tuples in a relation, Delete is used to delete tuples, and Update (or Modify) is used to change the values of some attributes in existing tuples Relational Data Model • Several options are available if a deletion operation causes a violation. • The first option, called restrict, is to reject the deletion. • The second option, called cascade, is to attempt to cascade (or propagate) the deletion by deleting tuples that reference the tuple that is being deleted. • The third option, called set null or set default, is to modify the referencing attribute values that cause the violation; • Updating an attribute that is neither part of a primary key nor part of a foreign key usually causes no problems; • A transaction is an executing program that includes some database operations, such as reading from the database, or applying insertions, deletions, or updates to the database. Thank you All Any Questions?