Lecture 19-Dbms-Lecture 4-2
Lecture 19-Dbms-Lecture 4-2
Data modelling, the first step in designing a database refers to the process of creating a specific data model for
a determined problem domain. Data models are communication tool that can facilitate interaction among the
designer, the applications programmer, and the end user.
Data models use three types of relationships: one-to-many (1:M), many-to-many (M:N), and one-to-one
(1:1):
• One-to-many (1:M) relationship. A painter creates many different paintings, but each is painted by
only one painter. Thus, the painter (the “one”) is related to the paintings (the “many”). Therefore, the
relationship “PAINTER paints PAINTING” is labelled as 1:M.
• Many-to-many (M:N) relationship. An employee may learn many job skills, and each job skill may be
learned by many employees. This relationship “EMPLOYEE learns SKILL” is labelled as M:N.
• One-to-one (1:1) relationship. A retail company’s management structure may require that each of its
stores be managed by a single employee. In turn, each store manager, who is an employee, manages
only a single store. Therefore, the relationship “EMPLOYEE manages STORE” is labeled 1:1.
The preceding discussion identified each relationship in both directions; that is, relationships are
bidirectional:
• One CUSTOMER can generate many INVOICEs.
• Each of the many INVOICEs is generated by only one CUSTOMER.
d. Constraint: A constraint is a restriction placed on the data. Constraints are important because they
help to ensure data integrity. Constraints are normally expressed in the form of rules. For example:
• An employee’s salary must have values that are between 6,000 and 350,000.
• A student’s GPA must be between 0.00 and 4.00.
Business Rules
A business rule is a brief, precise, and unambiguous description of a policy, procedure, or principle within a
specific organization. Business rules apply to any organization. Examples of business rules are as follows:
• A customer may generate many invoices.
• An invoice is generated by only one customer.
• A training session cannot be scheduled for fewer than 10 employees or for more than 30 employees.
1
The business rules establish entities, relationships, and constraints. For example, the first two business rules
establish two entities (CUSTOMER and INVOICE) and the type of relationship between those two entities. The
third business rule establishes a constraint (no fewer than 10 people and no more than 30 people), two
entities (EMPLOYEE and TRAINING), and a relationship between EMPLOYEE and TRAINING.
To properly identify the type of relationship, you should consider that relationships are bidirectional; that is,
they go both ways. For example, the business rule “a customer may generate many invoices” is
complemented by the business rule “an invoice is generated by only one customer.” In that case, the
relationship is one-to-many (1:M). Customer is the “1” side, and invoice is the “many” side.
Retrieving the data in a hierarchical database requires navigating through the records, moving up, down, and
sideways one record at a time.
2
Consider the example of database containing of record structure Supplier, Parts and Shipment given by Table
below. The possible hierarchical view is shown in Figure 20.2. There are 4 individual trees, a tree for each part.
The tree structure has parts superior to suppliers. This means that Parts form the parent and Supplier form the
children.
(a) (b)
(c) (d)
Figure 20.2: Example of the Hierarchical Data Model
Each of the four trees in the Figure 20.2 consists of one Part record occurrence, together with a set of
subordinate Supplier record occurrence. There is one supplier record for each supplier of a particular part.
Each supplier occurrence includes the corresponding shipment quantity, for example, supplier S3 supplies 300
quantities of part P2 (Figure 20.2b). Note that the set of supplier occurrences for a given part occurrences may
contain any number of members including zero (Figure 20.2d). It can be seen that part P1 is supplied by two
suppliers S1 and S2; part P2 is supplied by three suppliers S1, S2 and S3; and part P3 is supplied by only one
supplier S1.
3
• Cannot represent all the relationship that occur in the real-world
• Cannot demonstrate the overall data model for the enterprise because actual data may not be available at
time of designing the data model
• Can be used only when there is a hierarchical feature in the concerned database
• Cannot represent M:N relationship
• Insertion, deletion and updation results in inconsistency
Network databases had their disadvantages too, these were very rigid; the set of relationships and the
structure of the records had to be specified in advance; changing the database structure required rebuilding
the entire database.
4
The most important advantage of the RDBMS is its ability to hide the complexities of the relational model
from the user. The RDBMS manages all of the physical details, while the user sees the relational database as a
collection of tables in which data are stored. The user can manipulate and query the data in a way that seems
intuitive and logical.
Tables are related to each other through the sharing of a common attribute (a value in a column). For
example, the BOOK table (Figure 5) contains the author’s-id that is also contained in the AUTHOR table.
The common link between the BOOK and AUTHOR tables enables to match the book to the author, even
though the book data are stored in one table and the author data are stored in another table. For example, it
can easily be determine that the book Database Management is written by C. J. Date because for this book,
the BOOK table’s AUHTOR_ID is 501, which matches the AUTHOR table’s AUHTOR_ID for C. J. Date. Although
the tables are independent of one another, you can easily associate the data between tables. The relational
model provides a minimum level of controlled redundancy to eliminate most of the redundancies commonly
found in file systems.
The relationship type (1:1, 1:M, or M:N) is often shown in a relational schema. A relational diagram is a
representation of the relational database’s entities, the attributes within those entities, and the relationships
between those entities.
The reason for relational data model’s popularity is its powerful and flexible query language. Most relational
database software uses Structured Query Language (SQL) which allows the user to specify what must be done
without specifying how. The RDBMS uses SQL to translate user queries into instructions for retrieving the
requested data. SQL makes it possible to retrieve data with far less effort than any other database or file
environment.
5
3. Each table column represents an attribute, and each column has a distinct name.
4. Each intersection of a row and column represents a single data value.
5. All values in a column must conform to the same data format.
6. Each column has a specific range of values known as the attribute domain.
7. The order of the rows and columns is immaterial to the DBMS.
8. Each table must have an attribute or combination of attributes that uniquely identifies each row.
The table shown in Figure 20.6 illustrates the characteristics listed above:
Using the STUDENT table shown in Figure 6, the following conclusions can be drawn:
1. The STUDENT table is perceived to be a two-dimensional structure composed of four rows (tuples) and 9
columns (attributes).
2. Each row in the STUDENT table describes a single entity occurrence within the entity set. (The entity set is
represented by the STUDENT table.) For example, row 1 in Figure 20.6 describes a student named Ayushi
Gupta. Given the table contents, the STUDENT entity set includes 4 distinct entities (rows), or students.
3. Each column represents an attribute, and each column has a distinct name.
4. All of the values in a column match the attribute’s characteristics. For example, the grade point average
(STU_GPA) column contains only STU_GPA entries for each of the table rows. Data must be classified
according to their format and function.
Although various DBMSs can support different data types, most support at least the following:
a. Numeric: Numeric data can be used to perform meaningful arithmetic procedures. For example, in the
Figure STU_GPA is a numeric attribute.
b. Character: Character data, also known as text data or string data, can contain any character or symbol
not intended for mathematical manipulation. In the Figure STU_CLASS is an example of character
attribute.
c. Date: Date attributes contain calendar dates stored in a special format known as the Julian date
format. In the Figure, STU_DOB is a date attribute.
d. Logical: Logical data can only have true or false (yes or no) values. In Figure 20.6, the STU_TRANSFER
attribute uses a logical data format.
5. The column’s range of permissible values is known as its domain. Because the STU_GPA values are limited
to the range 0–9, inclusive, the domain is [0,9].
6. The order of rows and columns is immaterial to the user.
7. Each table must have a primary key. In general terms, the primary key is an attribute or combination of
attributes that uniquely identifies any given row. In this case, STU_RNO (the student roll number) is the
primary key. Using the data in Figure 20.6, observe that a student’s last name (STU_LNAME) would not be
6
a good primary key because several students have the last name of Gupta. Even the combination of the
last name and first name (STU_FNAME) would not be an appropriate primary key because more than one
student is named Ayushi Gupta.
Primary Key
A Candidate Key that is used by the database designer for unique identification of each row in a table is
known as Primary Key. A Primary Key can consist of one or more attributes of a table. Example includes
STDU_RNO.
In addition to its role in providing a unique identity to each row in the table, the primary key may play an
additional role in the controlled redundancy that allows the relational model to work.
Foreign key
A foreign key is the primary key of one table that has been placed into another table to create a common
attribute. A foreign key is an attribute or combination of attribute in one base table that points to the
candidate key (generally it is the primary key) of another table. The purpose of the foreign key is to ensure
referential integrity of the data i.e. only values that are supposed to appear in the database are permitted.
One advantage of using a proper naming convention for table attributes is that you can identify foreign
keys more easily. From the STUDENT table in Figure 6 two foreign keys can be identified (DEPT_CODE and
PROF_NUM) that imply the existence of two other tables in the database (DEPARTMENT and PROFESSOR)
related to STUDENT.