0% found this document useful (0 votes)
607 views

IM201-Fundamentals of Database Systems

This document provides an overview of database system concepts and architecture. It defines key terms like data models, schemas, and instances. It describes the evolution of database architectures from centralized mainframes to modern distributed and cloud-based systems. The objectives are to define data models and schemas, describe DBMS functionality from a user perspective, discuss interfaces and languages, and classify different types of DBMS packages. The discussion focuses on data abstraction through data models, categories of data models, and the distinction between schemas that define a database and instances that comprise the actual database contents and state.

Uploaded by

Jc Barrera
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
607 views

IM201-Fundamentals of Database Systems

This document provides an overview of database system concepts and architecture. It defines key terms like data models, schemas, and instances. It describes the evolution of database architectures from centralized mainframes to modern distributed and cloud-based systems. The objectives are to define data models and schemas, describe DBMS functionality from a user perspective, discuss interfaces and languages, and classify different types of DBMS packages. The discussion focuses on data abstraction through data models, categories of data models, and the distinction between schemas that define a database and instances that comprise the actual database contents and state.

Uploaded by

Jc Barrera
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 169

IM 201

Fundamentals of Database Systems

Learning Module on IM 201


23

M1:L1 Exercise
a. Define the following terms: data, database, DBMS, database system, database catalog, program-data
independence, user view, DBA, end user, canned transaction, deductive database system, persistent object, meta-
data, and transaction-processing application.

b. What four main types of actions involve databases? Briefly discuss each.

c. Discuss the main characteristics of the database approach and how it differs from traditional file systems.

Learning Module on IM 201


24

d. Discuss the capabilities that should be provided by a DBMS.

e. Discuss the differences between database systems and information retrieval systems.

M1:L1 Application
a. Cite some examples of integrity constraints that you think can apply to the database shown in Figure 1.2.

Learning Module on IM 201


25

b. Give examples of systems in which it may make sense to use traditional file
processing instead of a database approach.

Learning Module on IM 201


26

Summary of the Lesson:


1. In this chapter we defined a database as a collection of related data, where data means recorded facts. A typical
database represents some aspect of the real world and is used for specific purposes by one or more groups of
users. A DBMS is a generalized software package for implementing and maintaining a computerized database.
The database and software together form a database system.
2. We identified several characteristics that distinguish the database approach from traditional file-processing
applications, and we discussed the main categories of database users, or the actors on the scene. We noted that in
addition to database users, there are several categories of support personnel, or workers behind the scene, in a
database environment.
3. We presented a list of capabilities that should be provided by the DBMS software to the DBA, database
designers, and end users to help them design, administer, and use a database. Then we gave a brief historical
perspective on the evolution of database applications. We pointed out the recent rapid growth of the amounts and
types of data that must be stored in databases, and we discussed the emergence of new systems for handling “big
data” applications. Finally, we discussed the overhead costs of using a DBMS and discussed some situations in
which it may not be advantageous to use one.

Learning Module on IM 201


27

M1:L1 Enrichment Activity


a. If the name of the ‘CS’ (Computer Science) Department changes to ‘CSSE’ (Computer Science and Software
Engineering) Department and the corresponding prefix for the course number also changes, identify the columns
in the database that would need to be updated.

b. Give a one sentence description of each of the tasks you listed for question number 1.

Learning Module on IM 201


28

Lesson 2. Database System Concepts and Architecture


The architecture of DBMS packages has evolved from the early monolithic systems, where the whole DBMS
software package was one tightly integrated system, to the modern DBMS packages that are modular in design,
with a client/server system architecture. The recent growth in the amount of data requiring storage has led to
database systems with distributed architectures comprised of thousands of computers that manage the data stores.
This evolution mirrors the trends in computing, where large centralized mainframe computers are replaced by
hundreds of distributed workstations and personal computers connected via communications networks to various
types of server machines—Web servers, database servers, file servers, application servers, and so on. The current
cloud computing environments consist of thousands of large servers managing so-called big data for users on the
Web.
Lesson Objectives:
Once you have mastered the material in this chapter you will be able to:

1. define data models and defines the concepts of schemas and instances, which are fundamental to the study of
database systems. We discuss the three-schema DBMS architecture and data independence;
2. provides a user’s perspective on what a DBMS is supposed to do;
3. describe the types of interfaces and languages that are typically provided by a DBMS;
4. discuss the database system software environment;
5. give an overview of various types of client/server architectures;
6. present a classification of the types of DBMS packages.
Discussion:
Data Models, Schemas, and Instances
One fundamental characteristic of the database approach is that it provides some level of data abstraction. Data
abstraction generally refers to the suppression of details of data organization and storage, and the highlighting of
the essential features for an improved understanding of data. One of the main characteristics of the database
approach is to support data abstraction so that different users can perceive data at their preferred level of detail.
A data model—a collection of concepts that can be used to describe the structure of a database—provides the
necessary means to achieve this abstraction.2 By structure of a database we mean the data types, relationships,
and constraints that apply to the data. Most data models also include a set of basic operations for specifying
retrievals and updates on the database.
In addition to the basic operations provided by the data model, it is becoming more common to include concepts
in the data model to specify the dynamic aspect or behavior of a database application. This allows the database
designer to specify a set of valid user-defined operations that are allowed on the database objects. An example of
a user-defined operation could be COMPUTE_GPA, which can be applied to a STUDENT object. On the other

Learning Module on IM 201


29

hand, generic operations to insert, delete, modify, or retrieve any kind of object are often included in the basic
data model operations.
Categories of Data Models
Many data models have been proposed, which we can categorize according to the types of concepts they use to
describe the database structure. High-level or conceptual data models provide concepts that are close to the way
many users perceive data, whereas low-level or physical data models provide concepts that describe the details
of how data is stored on the computer storage media, typically magnetic disks. Concepts provided by physical
data models are generally meant for computer specialists, not for end users. Between these two extremes is a class
of representational (or implementation) data models,4 which provide concepts that may be easily understood by
end users but that are not too far removed from the way data is organized in computer storage. Representational
data models hide many details of data storage on disk but can be implemented on a computer system directly.
Conceptual data models use concepts such as entities, attributes, and relationships. An entity represents a real-
world object or concept, such as an employee or a project from the miniworld that is described in the database.
An attribute represents some property of interest that further describes an entity, such as the employee’s name or
salary. A relationship among two or more entities represents an association among the entities, for example, a
works-on relationship between an employee and a project.
Schemas, Instances, and Database State
In a data model, it is important to distinguish between the description of the database and the database itself. The
description of a database is called the database schema, which is specified during database design and is not
expected to change frequently.6 Most data models have certain conventions for displaying schemas as diagrams.7
A displayed schema is called a schema diagram. Figure 2.1 shows a schema diagram for the database shown in
Figure 1.2; the diagram displays the structure of each record type but not the actual instances of records.

Learning Module on IM 201


30

We call each object in the schema—such as STUDENT or COURSE—a schema construct. A schema diagram
displays only some aspects of a schema, such as the names of record types and data items, and some types of
constraints. Other aspects are not specified in the schema diagram; for example, Figure 2.1 shows neither the data
type of each data item nor the relationships among the various files. Many types of constraints are not represented
in schema diagrams. A constraint such as students majoring in computer science must take CS1310 before the
end of their sophomore year is quite difficult to represent diagrammatically.
The actual data in a database may change quite frequently. For example, the database shown in Figure 1.2 changes
every time we add a new student or enter a new grade. The data in the database at a particular moment in time is
called a database state or snapshot. It is also called the current set of occurrences or instances in the database. In
a given database state, each schema construct has its own current set of instances; for example, the STUDENT
construct will contain the set of individual student entities (records) as its instances. Many database states can be
constructed to correspond to a particular database schema. Every time we insert or delete a record or change the
value of a data item in a record, we change one state of the database into another state.
The distinction between database schema and database state is very important. When we define a new database,
we specify its database schema only to the DBMS. At this point, the corresponding database state is the empty
state with no data. We get the initial state of the database when the database is first populated or loaded with the
initial data. From then on, every time an update operation is applied to the database, we get another database state.
At any point in time, the database has a current state.8 The DBMS is partly responsible for ensuring that every
state of the database is a valid state—that is, a state that satisfies the structure and constraints specified in the
schema. Hence, specifying a correct schema to the DBMS is extremely important and the schema must be
designed with utmost care. The DBMS stores the descriptions of the schema constructs and constraints—also

Learning Module on IM 201


31

called the meta-data—in the DBMS catalog so that DBMS software can refer to the schema whenever it needs
to. The schema is sometimes called the intension, and a database state is called an extension of the schema.
Although, as mentioned earlier, the schema is not supposed to change frequently, it is not uncommon that changes
occasionally need to be applied to the schema as the application requirements change. For example, we may
decide that another data item needs to be stored for each record in a file, such as adding the Date_of_birth to the
STUDENT schema in Figure 2.1. This is known as schema evolution. Most modern DBMSs include some
operations for schema evolution that can be applied while the database is operational.
Three-Schema Architecture and Data Independence
Three of the four important characteristics of the database approach, listed in lesson 1, are (1) use of a catalog to
store the database description (schema) so as to make it self-describing, (2) insulation of programs and data
(program-data and program-operation independence), and (3) support of multiple user views.
In this section we specify an architecture for database systems, called the three-schema architecture, that was
proposed to help achieve and visualize these characteristics. Then we discuss further the concept of data
independence.
The Three-Schema Architecture
The goal of the three-schema architecture, illustrated in Figure 2.2, is to separate the user applications from the
physical database. In this architecture, schemas can be defined at the following three levels:

1. The internal level has an internal schema, which describes the physical storage structure of the database. The
internal schema uses a physical data model and describes the complete details of data storage and access paths
for the database.

Learning Module on IM 201


32

2. The conceptual level has a conceptual schema, which describes the structure of the whole database for a
community of users. The conceptual schema hides the details of physical storage structures and concentrates on
describing entities, data types, relationships, user operations, and constraints. Usually, a representational data
model is used to describe the conceptual schema when a database system is implemented. This implementation
conceptual schema is often based on a conceptual schema design in a high-level data model.
3. The external or view level includes a number of external schemas or user views. Each external schema describes
the part of the database that a particular user group is interested in and hides the rest of the database from that
user group. As in the previous level, each external schema is typically implemented using a representational data
model, possibly based on an external schema design in a high-level conceptual data model.
The three-schema architecture is a convenient tool with which the user can visualize the schema levels in a
database system. Most DBMSs do not separate the three levels completely and explicitly, but they support the
three-schema architecture to some extent. Some older DBMSs may include physical-level details in the
conceptual schema. The three-level ANSI architecture has an important place in database technology
development because it clearly separates the users’ external level, the database’s conceptual level, and the internal
storage level for designing a database.
It is very much applicable in the design of DBMSs, even today. In most DBMSs that support user views, external
schemas are specified in the same data model that describes the conceptual-level information (for example, a
relational DBMS like Oracle or SQL Server uses SQL for this).
Notice that the three schemas are only descriptions of data; the actual data is stored at the physical level only. In
the three-schema architecture, each user group refers to its own external schema. Hence, the DBMS must
transform a request specified on an external schema into a request against the conceptual schema, and then into a
request on the internal schema for processing over the stored database. If the request is a database retrieval, the
data extracted from the stored database must be reformatted to match the user’s external view. The processes of
transforming requests and results between levels are called mappings. These mappings may be time-consuming,
so some DBMSs—especially those that are meant to support small databases—do not support external views.
Even in such systems, however, it is necessary to transform requests between the conceptual and internal levels.
Data Independence
The three-schema architecture can be used to further explain the concept of data independence, which can be
defined as the capacity to change the schema at one level of a database system without having to change the
schema at the next higher level. We can define two types of data independence:
1. Logical data independence is the capacity to change the conceptual schema without having to change external
schemas or application programs. We may change the conceptual schema to expand the database (by adding a
record type or data item), to change constraints, or to reduce the database (by removing a record type or data
item). In the last case, external schemas that refer only to the remaining data should not be affected. For example,
the external schema of Figure 1.5(a) should not be affected by changing the GRADE_REPORT file (or record
type) shown in Figure 1.2 into the one shown in Figure 1.6(a). Only the view definition and the mappings need
to be changed in a DBMS that supports logical data independence. After the conceptual schema undergoes a

Learning Module on IM 201


33

logical reorganization, application programs that reference the external schema constructs must work as before.
Changes to constraints can be applied to the conceptual schema without affecting the external schemas or
application programs.
2. Physical data independence is the capacity to change the internal schema without having to change the
conceptual schema. Hence, the external schemas need not be changed as well. Changes to the internal schema
may be needed because some physical files were reorganized—for example, by creating additional access
structures—to improve the performance of retrieval or update. If the same data as before remains in the database,
we should not have to change the conceptual schema. For example, providing an access path to improve retrieval
speed of SECTION records (Figure 1.2) by semester and year should not require a query such as list all sections
offered in fall 2008 to be changed, although the query would be executed more efficiently by the DBMS by
utilizing the new access path.
Generally, physical data independence exists in most databases and file environments where physical details, such
as the exact location of data on disk, and hardware details of storage encoding, placement, compression, splitting,
merging of records, and so on are hidden from the user. Applications remain unaware of these details. On the
other hand, logical data independence is harder to achieve because it allows structural and constraint changes
without affecting application programs—a much stricter requirement.
Whenever we have a multiple-level DBMS, its catalog must be expanded to include information on how to map
requests and data among the various levels. The DBMS uses additional software to accomplish these mappings
by referring to the mapping information in the catalog. Data independence occurs because when the schema is
changed at some level, the schema at the next higher level remains unchanged; only the mapping between the two
levels is changed. Hence, application programs referring to the higher-level schema need not be changed.
Database Languages and Interfaces
The DBMS must provide appropriate languages and interfaces for each category of users. In this section we
discuss the types of languages and interfaces provided by a DBMS and the user categories targeted by each
interface.
DBMS Languages
Once the design of a database is completed and a DBMS is chosen to implement the database, the first step is to
specify conceptual and internal schemas for the database and any mappings between the two. In many DBMSs
where no strict separation of levels is maintained, one language, called the data definition language (DDL), is
used by the DBA and by database designers to define both schemas. The DBMS will have a DDL compiler whose
function is to process DDL statements in order to identify descriptions of the schema constructs and to store the
schema description in the DBMS catalog.
In DBMSs where a clear separation is maintained between the conceptual and internal levels, the DDL is used to
specify the conceptual schema only. Another language, the storage definition language (SDL), is used to specify
the internal schema. The mappings between the two schemas may be specified in either one of these languages.
In most relational DBMSs today, there is no specific language that performs the role of SDL. Instead, the internal
schema is specified by a combination of functions, parameters, and specifications related to storage of files. These

Learning Module on IM 201


34

permit the DBA staff to control indexing choices and mapping of data to storage. For a true three-schema
architecture, we would need a third language, the view definition language (VDL), to specify user views and their
mappings to the conceptual schema, but in most DBMSs the DDL is used to define both conceptual and external
schemas. In relational DBMSs, SQL is used in the role of VDL to define user or application views as results of
predefined queries.
Once the database schemas are compiled and the database is populated with data, users must have some means to
manipulate the database. Typical manipulations include retrieval, insertion, deletion, and modification of the data.
The DBMS provides a set of operations or a language called the data manipulation language (DML) for these
purposes.
In current DBMSs, the preceding types of languages are usually not considered distinct languages; rather, a
comprehensive integrated language is used that includes constructs for conceptual schema definition, view
definition, and data manipulation.
Storage definition is typically kept separate, since it is used for defining physical storage structures to fine-tune
the performance of the database system, which is usually done by the DBA staff. A typical example of a
comprehensive database language is the SQL relational database language, which represents a combination of
DDL, VDL, and DML, as well as statements for constraint specification, schema evolution, and many other
features. The SDL was a component in early versions of SQL but has been removed from the language to keep it
at the conceptual and external levels only.
There are two main types of DMLs. A high-level or nonprocedural DML can be used on its own to specify
complex database operations concisely. Many DBMSs allow high-level DML statements either to be entered
interactively from a display monitor or terminal or to be embedded in a general-purpose programming language.
In the latter case, DML statements must be identified within the program so that they can be extracted by a pre-
compiler and processed by the DBMS. A low level or procedural DML must be embedded in a general-purpose
programming language. This type of DML typically retrieves individual records or objects from the database and
processes each separately. Therefore, it needs to use programming language constructs, such as looping, to
retrieve and process each record from a set of records. Low-level DMLs are also called record-at-a-time DMLs
because of this property. High-level DMLs, such as SQL, can specify and retrieve many records in a single DML
statement; therefore, they are called set-at-a-time or set-oriented DMLs. A query in a high-level DML often
specifies which data to retrieve rather than how to retrieve it; therefore, such languages are also called declarative.
Whenever DML commands, whether high level or low level, are embedded in a general-purpose programming
language, that language is called the host language and the DML is called the data sublanguage.10 On the other
hand, a high-level DML used in a standalone interactive manner is called a query language. In general, both
retrieval and update commands of a high-level DML may be used interactively and are hence considered part of
the query language.
Casual end users typically use a high-level query language to specify their requests, whereas programmers use
the DML in its embedded form. For naive and parametric users, there usually are user-friendly interfaces for

Learning Module on IM 201


35

interacting with the database; these can also be used by casual users or others who do not want to learn the details
of a high-level query language.
DBMS INTERFACES
User-friendly interfaces provided by a DBMS may include the following: Menu-based Interfaces for Web Clients
or Browsing. These interfaces present the user with lists of options (called menus) that lead the user through the
formulation of a request. Menus do away with the need to memorize the specific commands and syntax of a query
language; rather, the query is composed step-by-step by picking options from a menu that is displayed by the
system. Pull-down menus are a very popular technique in Web-based user interfaces. They are also often used in
browsing interfaces, which allow a user to look through the contents of a database in an exploratory and
unstructured manner.
Apps for Mobile Devices. These interfaces present mobile users with access to their data. For example, banking,
reservations, and insurance companies, among many others, provide apps that allow users to access their data
through a mobile phone or mobile device. The apps have built-in programmed interfaces that typically allow users
to login using their account name and password; the apps then provide a limited menu of options for mobile access
to the user data, as well as options such as paying bills (for banks) or making reservations (for reservation Web
sites).
Forms-based Interfaces. A forms-based interface displays a form to each user. Users can fill out all of the form
entries to insert new data, or they can fill out only certain entries, in which case the DBMS will retrieve matching
data for the remaining entries. Forms are usually designed and programmed for naive users as interfaces to canned
transactions. Many DBMSs have forms specification languages, which are special languages that help
programmers specify such forms. SQL*Forms is a form-based language that specifies queries using a form
designed in conjunction with the relational database schema. Oracle Forms is a component of the Oracle product
suite that provides an extensive set of features to design and build applications using forms. Some systems have
utilities that define a form by letting the end user interactively construct a sample form on the screen.
Graphical User Interfaces. A GUI typically displays a schema to the user in diagrammatic form. The user then
can specify a query by manipulating the diagram. In many cases, GUIs utilize both menus and forms.
Natural Language Interfaces. These interfaces accept requests written in English or some other language and
attempt to understand them. A natural language interface usually has its own schema, which is similar to the
database conceptual schema, as well as a dictionary of important words. The natural language interface refers to
the words in its schema, as well as to the set of standard words in its dictionary, that are used to interpret the
request. If the interpretation is successful, the interface generates a high-level query corresponding to the natural
language request and submits it to the DBMS for processing; otherwise, a dialogue is started with the user to
clarify the request.
Keyword-based Database Search. These are somewhat similar to Web search engines, which accept strings of
natural language (like English or Spanish) words and match them with documents at specific sites (for local search
engines) or Web pages on the Web at large (for engines like Google or Ask). They use predefined indexes on
words and use ranking functions to retrieve and present resulting documents in a decreasing degree of match.

Learning Module on IM 201


36

Such “free form” textual query interfaces are not yet common in structured relational databases, although a
research area called keyword-based querying has emerged recently for relational databases. Speech Input and
Output. Limited use of speech as an input query and speech as an answer to a question or result of a request is
becoming commonplace. Applications with limited vocabularies, such as inquiries for telephone directory, flight
arrival/departure, and credit card account information, are allowing speech for input and output to enable
customers to access this information. The speech input is detected using a library of predefined words and used
to set up the parameters that are supplied to the queries. For output, a similar conversion from text or numbers
into speech takes place.
Interfaces for Parametric Users. Parametric users, such as bank tellers, often have a small set of operations that
they must perform repeatedly. For example, a teller is able to use single function keys to invoke routine and
repetitive transactions such as account deposits or withdrawals, or balance inquiries. Systems analysts and
programmers design and implement a special interface for each known class of naive users. Usually a small set
of abbreviated commands is included, with the goal of minimizing the number of keystrokes required for each
request.
Interfaces for the DBA. Most database systems contain privileged commands that can be used only by the DBA
staff. These include commands for creating accounts, setting system parameters, granting account authorization,
changing a schema, and reorganizing the storage structures of a database.
THE DATABASE SYSTEM ENVIRONMENT
A DBMS is a complex software system. In this section we discuss the types of software components that constitute
a DBMS and the types of computer system software with which the DBMS interacts.
DBMS Component Modules
Figure 2.3 illustrates, in a simplified form, the typical DBMS components. The figure is divided into two parts.
The top part of the figure refers to the various users of the database environment and their interfaces. The lower
part shows the internal modules of the DBMS responsible for storage of data and processing of transactions.
The database and the DBMS catalog are usually stored on disk. Access to the disk is controlled primarily by the
operating system (OS), which schedules disk read/write. Many DBMSs have their own buffer management
module to schedule disk read/write, because management of buffer storage has a considerable effect on
performance. Reducing disk read/write improves performance considerably.
A higher-level stored data manager module of the DBMS controls access to DBMS information that is stored on
disk, whether it is part of the database or the catalog. Let us consider the top part of Figure 2.3 first. It shows
interfaces for the DBA staff, casual users who work with interactive interfaces to formulate queries, application
programmers who create programs using some host programming languages, and parametric users who do data
entry work by supplying parameters to predefined transactions. The DBA staff works on defining the database
and tuning it by making changes to its definition using the DDL and other privileged commands.

Learning Module on IM 201


37

The DDL compiler processes schema definitions, specified in the DDL, and stores descriptions of the schemas
(meta-data) in the DBMS catalog. The catalog includes information such as the names and sizes of files, names
and data types of data items, storage details of each file, mapping information among schemas, and constraints.

In addition, the catalog stores many other types of information that are needed by the DBMS modules, which can
then look up the catalog information as needed. Casual users and persons with occasional need for information
from the database interact using the interactive query interface in Figure 2.3. We have not explicitly shown any
menu-based or form-based or mobile interactions that are typically used to generate the interactive query
automatically or to access canned transactions.
These queries are parsed and validated for correctness of the query syntax, the names of files and data elements,
and so on by a query compiler that compiles them into an internal form. This internal query is subjected to query
optimization. Among other things, the query optimizer is concerned with the rearrangement and possible
reordering of operations, elimination of redundancies, and use of efficient search algorithms during execution. It
consults the system catalog for statistical and other physical information about the stored data and generates
executable code that performs the necessary operations for the query and makes calls on the runtime processor.

Learning Module on IM 201


38

Application programmers write programs in host languages such as Java, C, or C++ that are submitted to a pre-
compiler. The pre-compiler extracts DML commands from an application program written in a host programming
language. These commands are sent to the DML compiler for compilation into object code for database access.
The rest of the program is sent to the host language compiler. The object codes for the DML commands and the
rest of the program are linked, forming a canned transaction whose executable code includes calls to the runtime
database processor. It is also becoming increasingly common to use scripting languages such as PHP and Python
to write database programs. Canned transactions are executed repeatedly by parametric users via PCs or mobile
apps; these users simply supply the parameters to the transactions. Each execution is considered to be a separate
transaction. An example is a bank payment transaction where the account number, payee, and amount may be
supplied as parameters.
In the lower part of Figure 2.3, the runtime database processor executes (1) the privileged commands, (2) the
executable query plans, and (3) the canned transactions with runtime parameters. It works with the system catalog
and may update it with statistics. It also works with the stored data manager, which in turn uses basic operating
system services for carrying out low-level input/output (read/write) operations between the disk and main
memory. The runtime database processor handles other aspects of data transfer, such as management of buffers
in the main memory. Some DBMSs have their own buffer management module whereas others depend on the OS
for buffer management. We have shown concurrency control and backup and recovery systems separately as a
module in this figure. They are integrated into the working of the runtime database processor for purposes of
transaction management.
It is common to have the client program that accesses the DBMS running on a separate computer or device from
the computer on which the database resides. The former is called the client computer running DBMS client
software and the latter is called the database server. In many cases, the client accesses a middle computer, called
the application server, which in turn accesses the database server. Figure 2.3 is not meant to describe a specific
DBMS; rather, it illustrates typical DBMS modules. The DBMS interacts with the operating system when disk
accesses— to the database or to the catalog—are needed. If the computer system is shared by many users, the OS
will schedule DBMS disk access requests and DBMS processing along with other processes. On the other hand,
if the computer system is mainly dedicated to running the database server, the DBMS will control main memory
buffering of disk pages. The DBMS also interfaces with compilers for general purpose host programming
languages, and with application servers and client programs running on separate machines through the system
network interface.
Database System Utilities
In addition to possessing the software modules just described, most DBMSs have database utilities that help the
DBA manage the database system. Common utilities have the following types of functions:
■ Loading. A loading utility is used to load existing data files—such as text files or sequential files—into the
database. Usually, the current (source) format of the data file and the desired (target) database file structure are
specified to the utility, which then automatically reformats the data and stores it in the database. With the
proliferation of DBMSs, transferring data from one DBMS to another is becoming common in many

Learning Module on IM 201


39

organizations. Some vendors offer conversion tools that generate the appropriate loading programs, given the
existing source and target database storage descriptions (internal schemas).
■ Backup. A backup utility creates a backup copy of the database, usually by dumping the entire database onto
tape or other mass storage medium. The backup copy can be used to restore the database in case of catastrophic
disk failure. Incremental backups are also often used, where only changes since the previous backup are recorded.
Incremental backup is more complex, but saves storage space.
■ Database storage reorganization. This utility can be used to reorganize a set of database files into different
file organizations and create new access paths to improve performance.
■ Performance monitoring. Such a utility monitors database usage and provides statistics to the DBA. The DBA
uses the statistics in making decisions such as whether or not to reorganize files or whether to add or drop indexes
to improve performance.
Other utilities may be available for sorting files, handling data compression, monitoring access by users,
interfacing with the network, and performing other functions.
Tools, Application Environments, and Communications Facilities
Other tools are often available to database designers, users, and the DBMS. CASE tools are used in the design
phase of database systems. Another tool that can be quite useful in large organizations is an expanded data
dictionary (or data repository) system. In addition to storing catalog information about schemas and constraints,
the data dictionary stores other information, such as design decisions, usage standards, application program
descriptions, and user information. Such a system is also called an information repository. This information can
be accessed directly by users or the DBA when needed. A data dictionary utility is similar to the DBMS catalog,
but it includes a wider variety of information and is accessed mainly by users rather than by the DBMS software.
Application development environments, such as PowerBuilder (Sybase) or JBuilder (Borland), have been quite
popular. These systems provide an environment for developing database applications and include facilities that
help in many facets of database systems, including database design, GUI development, querying and updating,
and application program development.
The DBMS also needs to interface with communications software, whose function is to allow users at locations
remote from the database system site to access the database through computer terminals, workstations, or personal
computers. These are connected to the database site through data communications hardware such as Internet
routers, phone lines, long-haul networks, local networks, or satellite communication devices. Many commercial
database systems have communication packages that work with the DBMS. The integrated DBMS and data
communications system is called a DB/DC system. In addition, some distributed DBMSs are physically
distributed over multiple machines. In this case, communications networks are needed to connect the machines.
These are often local area networks (LANs), but they can also be other types of networks.
Centralized and Client/Server Architectures for DBMSs
Centralized DBMSs Architecture

Learning Module on IM 201


40

Architectures for DBMSs have followed trends similar to those for general computer system architectures. Older
architectures used mainframe computers to provide the main processing for all system functions, including user
application programs and user interface programs, as well as all the DBMS functionality. The reason was that in
older systems, most users accessed the DBMS via computer terminals that did not have processing power and
only provided display capabilities.
Therefore, all processing was performed remotely on the computer system housing the DBMS, and only display
information and controls were sent from the computer to the display terminals, which were connected to the
central computer via various types of communications networks.
As prices of hardware declined, most users replaced their terminals with PCs and workstations, and more recently
with mobile devices. At first, database systems used these computers similarly to how they had used display
terminals, so that the
DBMS itself was still a centralized DBMS in which all the DBMS functionality, application program execution,
and user interface processing were carried out on one machine. Figure 2.4 illustrates the physical components in
a centralized architecture. Gradually, DBMS systems started to exploit the available processing power at the user
side, which led to client/server DBMS architectures.

Basic Client/Server Architectures


First, we discuss client/server architecture in general; then we discuss how it is applied to DBMSs. The
client/server architecture was developed to deal with computing environments in which a large number of PCs,
workstations, file servers, printers, database servers, Web servers, e-mail servers, and other software and
equipment are connected via a network. The idea is to define specialized servers with specific functionalities. For
example, it is possible to connect a number of PCs or small workstations as clients to a file server that maintains
the files of the client

Learning Module on IM 201


41

machines. Another machine can be designated as a printer server by being connected to various printers; all print
requests by the clients are forwarded to this machine. Web servers or e-mail servers also fall into the specialized
server category. The resources provided by specialized servers can be accessed by many client machines. The
client machines provide the user with the appropriate interfaces to utilize these servers, as well as with local
processing power to run local applications.
This concept can be carried over to other software packages, with specialized programs— such as a CAD
(computer-aided design) package—being stored on specific server machines and being made accessible to
multiple clients. Figure 2.5 illustrates client/server architecture at the logical level; Figure 2.6 is a simplified
diagram that shows the physical architecture. Some machines would be client sites only (for example, mobile
devices or workstations/PCs that have only client software installed). Other machines would be dedicated servers,
and others would have both client and server functionality.

The concept of client/server architecture assumes an underlying framework that consists of many
PCs/workstations and mobile devices as well as a smaller number of server machines, connected via wireless
networks or LANs and other types of computer networks. A client in this framework is typically a user machine
that provides user interface capabilities and local processing. When a client requires access to additional
functionality—such as database access—that does not exist at the client, it connects to a server that provides the
needed functionality. A server is a system containing both hardware and software that can provide services to the
client machines, such as file access, printing, archiving, or database access. In general, some machines install
only client software, others only server software, and still others may include both client and server software, as
illustrated in Figure 2.6.
However, it is more common that client and server software usually run on separate machines. Two main types
of basic DBMS architectures were created on this underlying client/server framework: two-tier and three-tier.

Learning Module on IM 201


42

Two-Tier Client/Server Architectures for DBMSs


In relational database management systems (RDBMSs), many of which started as centralized systems, the system
components that were first moved to the client side were the user interface and application programs. Because
SQL provided a standard language for RDBMSs, this created a logical dividing point between client and server.
Hence, the query and transaction functionality related to SQL processing remained on the server side. In such an
architecture, the server is often called a query server or transaction server because it provides these two
functionalities. In an RDBMS, the server is also often called an SQL server.
The user interface programs and application programs can run on the client side. When DBMS access is required,
the program establishes a connection to the DBMS (which is on the server side); once the connection is created,
the client program can communicate with the DBMS. A standard called Open Database Connectivity (ODBC)
provides an application programming interface (API), which allows client-side programs to call the DBMS, as
long as both client and server machines have the necessary software installed. Most DBMS vendors provide
ODBC drivers for their systems. A client program can actually connect to several RDBMSs and send query and
transaction requests using the ODBC API, which are then processed at the server sites. Any query results are sent
back to the client program, which can process and display the results as needed. A related standard for the Java
programming language, called JDBC, has also been defined.
This allows Java client programs to access one or more DBMSs through a standard interface. The architectures
described here are called two-tier architectures because the software components are distributed over two systems:
client and server. The advantages of this architecture are its simplicity and seamless compatibility with existing
systems. The emergence of the Web changed the roles of clients and servers, leading to the three-tier architecture.
Three-Tier and n-Tier Architectures for Web Applications
Many Web applications use an architecture called the three-tier architecture, which adds an intermediate layer
between the client and the database server, as illustrated in Figure 2.7(a).

Learning Module on IM 201


43

This intermediate layer or middle tier is called the application server or the Web server, depending on the
application. This server plays an intermediary role by running application programs and storing business rules
(procedures or constraints) that are used to access data from the database server. It can also improve database
security by checking a client’s credentials before forwarding a request to the database server. Clients contain user
interfaces and Web browsers. The intermediate server accepts requests from the client, processes the request and
sends database queries and commands to the database server, and then acts as a conduit for passing (partially)
processed data from the database server to the clients, where it may be processed further and filtered to be
presented to the users. Thus, the user interface, application rules, and data access act as the three tiers. Figure
2.7(b) shows another view of the three-tier architecture used by database and other application package vendors.
The presentation layer displays information to the user and allows data entry. The business logic layer handles
intermediate rules and constraints before data is passed up to the user or down to the DBMS. The bottom layer
includes all data management services. The middle layer can also act as a Web server, which retrieves query
results from the database server and formats them into dynamic
Web pages that are viewed by the Web browser at the client side. The client machine is typically a PC or mobile
device connected to the Web. Other architectures have also been proposed. It is possible to divide the layers
between the user and the stored data further into finer components, thereby giving rise to n-tier architectures,
where n may be four or five tiers. Typically, the business logic layer is divided into multiple layers. Besides
distributing programming and data throughout a network, n-tier applications afford the advantage that any one
tier can run on an appropriate processor or operating system platform and can be handled independently. Vendors
of ERP (enterprise resource planning) and CRM (customer relationship management) packages often use a
middleware layer, which accounts for the front-end modules (clients) communicating with a number of back-end
databases (servers).
Advances in encryption and decryption technology make it safer to transfer sensitive data from server to client in
encrypted form, where it will be decrypted. The latter can be done by the hardware or by advanced software. This
technology gives higher levels of data security, but the network security issues remain a major concern. Various

Learning Module on IM 201


44

technologies for data compression also help to transfer large amounts of data from servers to clients over wired
and wireless networks.
Classification of Database Management Systems
Several criteria can be used to classify DBMSs. The first is the data model on which the DBMS is based. The
main data model used in many current commercial DBMSs is the relational data model, and the systems based
on this model are known as SQL systems. The object data model has been implemented in some commercial
systems but has not had widespread use. Recently, so-called big data systems, also known as key-value storage
systems and NOSQL systems, use various data models: document-based, graph-based, column-based, and key-
value data models. Many legacy applications still run on database systems based on the hierarchical and network
data models.
The relational DBMSs are evolving continuously, and, in particular, have been incorporating many of the concepts
that were developed in object databases. This has led to a new class of DBMSs called object-relational DBMSs.
We can categorize DBMSs based on the data model: relational, object, object-relational, NOSQL, key-value,
hierarchical, network, and other.
Some experimental DBMSs are based on the XML (eXtended Markup Language) model, which is a tree-
structured data model. These have been called native XML DBMSs. Several commercial relational DBMSs have
added XML interfaces and storage to their products.
The second criterion used to classify DBMSs is the number of users supported by the system. Single-user systems
support only one user at a time and are mostly used with PCs. Multiuser systems, which include the majority of
DBMSs, support concurrent multiple users.
The third criterion is the number of sites over which the database is distributed. A DBMS is centralized if the data
is stored at a single computer site. A centralized DBMS can support multiple users, but the DBMS and the
database reside totally at a single computer site. A distributed DBMS (DDBMS) can have the actual database and
DBMS software distributed over many sites connected by a computer network.
Big data systems are often massively distributed, with hundreds of sites. The data is often replicated on multiple
sites so that failure of a site will not make some data unavailable. Homogeneous DDBMSs use the same DBMS
software at all the sites, whereas heterogeneous DDBMSs can use different DBMS software at each site. It is also
possible to develop middleware software to access several autonomous preexisting databases stored under
heterogeneous DBMSs. This leads to a federated DBMS (or Multi-database system), in which the participating
DBMSs are loosely coupled and have a degree of local autonomy. Many DDBMSs use client-server architecture.
The fourth criterion is cost. It is difficult to propose a classification of DBMSs based on cost. Today we have
open source (free) DBMS products like MySQL and PostgreSQL that are supported by third-party vendors with
additional services. The main RDBMS products are available as free examination 30-day copy versions as well
as personal versions, which may cost under $100 and allow a fair amount of functionality. The giant systems are
being sold in modular form with components to handle distribution, replication, parallel processing, mobile
capability, and so on, and with a large number of parameters that must be defined for the configuration.

Learning Module on IM 201


45

Furthermore, they are sold in the form of licenses—site licenses allow unlimited use of the database system with
any number of copies running at the customer site. Another type of license limits the number of concurrent users
or the number of user seats at a location. Standalone single-user versions of some systems like Microsoft Access
are sold per copy or included in the overall configuration of a desktop or laptop. In addition, data warehousing
and mining features, as well as support for additional data types, are made available at extra cost. It is possible to
pay millions of dollars for the installation and maintenance of large database systems annually.
We can also classify a DBMS on the basis of the types of access path options for storing files. One well-known
family of DBMSs is based on inverted file structures. Finally, a DBMS can be general purpose or special purpose.
When performance is a primary consideration, a special-purpose DBMS can be designed and built for a specific
application; such a system cannot be used for other applications without major changes. Many airline reservations
and telephone directory systems developed in the past are special-purpose DBMSs. These fall into the category
of online transaction processing (OLTP) systems, which must support a large number of concurrent transactions
without imposing excessive delays.

Learning Module on IM 201


46

M1:L2 EXERCISE.
a. Define the following terms: data model, database schema, database state, internal schema, conceptual schema,
external schema, data independence, DDL, DML, SDL, VDL, query language, host language, data sublanguage,
database utility, catalog, client/server architecture, three-tier architecture, and n-tier architecture.

b. What is the difference between logical data independence and physical data independence? Which one is harder
to achieve? Why?

c. What is the difference between the two tier and three-tier client/server architecture.

Learning Module on IM 201


47

M1:L2 Application
If you were designing a Web-based system to make airline reservations and to sell airline tickets, which DBMS
Architecture would you choose from? Why? Why would the other architectures not be a good choice?

Learning Module on IM 201


48

Summary of the Lesson:


1. In this chapter we introduced the main concepts used in database systems. We defined a data model and we
distinguished three main categories:
■ High-level or conceptual data models (based on entities and relationships)
■ Low-level or physical data models
■ Representational or implementation data models (record-based, object oriented)
2. We distinguished the schema, or description of a database, from the database itself. The schema does not change
very often, whereas the database state changes every time data is inserted, deleted, or modified. Then we described
the three-schema DBMS architecture, which allows three schema levels:
■ An internal schema describes the physical storage structure of the database.
■ A conceptual schema is a high-level description of the whole database.
■ External schemas describe the views of different user groups.
3. A DBMS that cleanly separates the three levels must have mappings among the schemas to transform requests
and query results from one level to the next. Most DBMSs do not separate the three levels completely. We used
the three-schema architecture to define the concepts of logical and physical data independence.
4. Then we discussed the main types of languages and interfaces that DBMSs support.

Learning Module on IM 201


49

M1:L2 Enrichment Activity:


a. In addition to constraints relating the values of columns in one table to columns in another table, there are also
constraints that impose restrictions on values in a column or a combination of columns within a table. One such
constraint forces that a column or a group of columns must be unique across all rows in the table. For example,
in the STUDENT table, the StudentNumber column must be unique (to prevent two different students from having
the same StudentNumber). Identify the column or the group of columns in the other tables that must be unique
across all rows in the table.

Learning Module on IM 201


50

Lesson 3. Introduction to SQL


The SQL language may be considered one of the major reasons for the commercial success of relational databases.
Because it became a standard for relational databases, users were less concerned about migrating their database
applications from other types of database systems—for example, older network or hierarchical systems—to
relational systems. This is because even if the users became dissatisfied with the particular relational DBMS
product they were using, converting to another relational DBMS product was not expected to be too expensive
and time-consuming because both systems followed the same language standards. In practice, of course, there are
differences among various commercial relational DBMS packages. However, if the user is diligent in using only
those features that are part of the standard, and if two relational DBMSs faithfully support the standard, then
conversion between two systems should be simplified. Another advantage of having such a standard is that users
may write statements in a database application program that can access data stored in two or more relational
DBMSs without having to change the database sublanguage (SQL), as long as both/all of the relational DBMSs
support standard SQL.
Lesson Objectives:
Once you have mastered the material in this chapter you will be able to:
1. Understand the basic of SQL;
2. install the localhost server for executing SQL commands;
3. identity the operators and datatypes used in SQL.
Discussion:
Structured Query Language (SQL) is a standard language to write queries. It was developed under R Project by
IBM. SQL has a basic grammar and syntax. It was declared as a standard language to use by American Standard
National Institute(ANSI) and International Standard Organization(ISO). The functionality of SQL language is
virtually similar across the operating system platforms.
The name SQL is presently expanded as Structured Query Language. Originally, SQL was called SEQUEL
(Structured English QUEry Language) and was designed and implemented at IBM Research as the interface for
an experimental relational database system called SYSTEM R. SQL is now the standard language for commercial
relational DBMSs. The standardization of SQL is a joint effort by the American National Standards Institute
(ANSI) and the International Standards Organization (ISO), and the first SQL standard is called SQL-86 or SQL1.
A revised and much expanded standard called SQL-92 (also referred to as SQL2) was subsequently developed.
The next standard that is well-recognized is SQL:1999, which started out as SQL3. Additional updates to the
standard are SQL:2003 and SQL:2006, which added XML features among other updates to the language. Another
update in 2008 incorporated more object database features into SQL, and a further update is SQL:2011.
Using SQL doesn’t require programming experience, but programming experience helps one to conceptualize
what a particular SQL command will help to execute and retrieve SQL queries.
Characteristics and Benefits of Structured Query Language:

Learning Module on IM 201


51

The ANSI SQL provides with:


▪ Specific syntax and semantics of SQL data definition and data manipulation languages.
▪ It also provides with basic data structure and operations for designing, assessing, maintaining, controlling
and protecting SQL databases.
▪ Portability of database definition and application is also provided. Applications can be moved from one
machine to another.
▪ IS professionals share a common language and reduce training costs.
▪ Professionals can become proficient in its use and increase the productivity.
▪ It provides with longevity.
▪ It provides with reduced dependence on single vendor.

Rules to write commands:


▪ Table names cannot exceed 20 characters.
▪ Name of the table must be unique.
▪ Field names also must be unique.
▪ The field list and filed length must be enclosed in parentheses.
▪ The user must specify the field length and type.
▪ The field definitions must be separated with commas.
▪ SQL statements must end with a semicolon.

HOW TO INSTALL XAMPP ON WINDOWS?


XAMPP can be used to perform SQL commands, it is an Apache server distribution which has MySQL, PHP,
PERL, and some other software like phpMyAdmin. It's an extremely useful software which can be used to test a
website locally on a personal computer. Generally, people who use content management systems based mainly
on PHP and MySQL like WordPress, Drupal, Joomla, or ownCloud to run their blogs and websites find XAMPP
to be very useful to comfortably run a local server. So, in this guide we will show you how to install XAMPP on
Windows.
From the term XAMPP, you can see that X denotes cross platform (Operating systems like Windows, Mac OS
X, Linux, and Solaris), A denotes Apache server, M stands for MySQL, P stands for PHP, and the last P is for
PERL.
To install XAMPP in Windows 7/8/10, first you need to download the XAMPP installer for windows. To
download the XAMPP installer for windows, visit the URL https://www.apachefriends.org/download.html.
This page shows the latest version of XAMPP for windows. It also shows the versions of Apache, PHP, MySQL,
and other software included in this version of XAMPP.

Learning Module on IM 201


52

1. Now, go to the "Download" section in the page. Here, you will see XAMPP for Windows, Linux, and Mac OS
X. We can easily download the XAMPP installer for Windows.
Click on the Download link to download XAMPP as shown below.

2. After downloading the installer, double click on the executable(.exe) file to start the XAMPP installation
process. Click Yes, if User Account Control dialog box appears.
This dialog box below shows that you
should avoid installing XAMPP to
C:\Program Files. Click OK.

3. Select your language in the dialog box then click OK.


4. The XAMPP welcome wizard will appear.
Click Next to continue.

Learning Module on IM 201


53

5. Verify that the checkboxes are checked the same as the image below,
then click Next. It’s ok to install everything but not required.

6. Verify that the Destination Folder is set to C:\xampp, then click Install.
7. You will see the installation progresses. Wait for the process to complete.
8. Click Finish to finish the installation process.
9. The dialog box asks: Do you want to start the Control Panel now?
You can choose to start the Control Panel now. Checking the check box will directly open the XAMPP control
panel. Please see the Note below to know how to start XAMPP Control Panel.
The installation is complete.
Note: If you want to start XAMPP Control Panel next time, right-click on the XAMPP icon found in the desktop
or in the start menu, then select “Run as administrator”. Click "Yes" on the "User Account Control" popup.
10. If the XAMPP control panel is not already started, find the XAMPP control panel in the start menu or the its
desktop icon, right click on it and select "Run as administrator". Click "Yes" on the "User Account Control"
popup, and wait for the XAMPP control panel to start. You will see the XAMPP control panel running.
11. Click on the Start button next to Apache, and wait for apache to start. After the Apache has started, click on
the Start button next to MySQL. Wait for MySQL to start. Both Apache and MySQL are running now.

Learning Module on IM 201


54

12. Now, open your web browser like Internet Explorer, Mozilla Firefox or Google Chrome.
Type “localhost/phpmyadmin” in the address bar and click enter. You can now start executing your SQL query
on the SQL tab. Write your query then click GO button.

Learning Module on IM 201


55

SQL OPERATORS
SQL Arithmetic Operators
Operator Description
+ Add
- Subtract
* Multiply
/ Divide
% Modulo

SQL Bitwise Operators


Operator Description
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
SQL Comparison Operators

Learning Module on IM 201


56

Operator Description
= Equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
<> Not equal to

SQL Compound Operators


Operator Description
+= Add equals
-= Subtract equals
*= Multiply equals
/= Divide equals
%= Modulo equals
&= Bitwise AND equals
^-= Bitwise exclusive equals
|*= Bitwise OR equals

SQL Logical Operators


Operator Description
ALL TRUE if all of the subquery values meet the condition
AND TRUE if all the conditions separated by AND is TRUE
ANY TRUE if any of the subquery values meet the condition
BETWEEN TRUE if the operand is within the range of comparisons
EXISTS TRUE if the subquery returns one or more records

Learning Module on IM 201


57

IN TRUE if the operand is equal to one of a list of expressions


LIKE TRUE if the operand matches a pattern
NOT Displays a record if the condition(s) is NOT TRUE
OR TRUE if any of the conditions separated by OR is TRUE
SOME TRUE if any of the subquery values meet the condition

SQL Data Types for MySQL, and SQL Server


The data type of a column defines what value the column can hold: integer, character, money, date and time,
binary, and so on.
SQL Data Types
Each column in a database table is required to have a name and a data type.
An SQL developer must decide what type of data that will be stored inside each column when creating a table.
The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it
also identifies how SQL will interact with the stored data.
Note: Data types might have different names in different database. And even if the name is the same, the size and
other details may be different! Always check the documentation.
MySQL Data Types (Version 8.0)
In MySQL there are three main data types: string, numeric, and date and time.

String data types:

Data type Description

CHAR(size) A FIXED length string (can contain letters, numbers, and special characters).
The size parameter specifies the column length in characters - can be from 0 to 255.
Default is 1

Learning Module on IM 201


58

VARCHAR(size) A VARIABLE length string (can contain letters, numbers, and special characters).
The size parameter specifies the maximum column length in characters - can be from 0
to 65535

BINARY(size) Equal to CHAR(), but stores binary byte strings. The size parameter specifies the
column length in bytes. Default is 1

VARBINARY(size) Equal to VARCHAR(), but stores binary byte strings. The size parameter specifies the
maximum column length in bytes.

TINYBLOB For BLOBs (Binary Large OBjects). Max length: 255 bytes

TINYTEXT Holds a string with a maximum length of 255 characters

TEXT(size) Holds a string with a maximum length of 65,535 bytes

BLOB(size) For BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data

MEDIUMTEXT Holds a string with a maximum length of 16,777,215 characters

MEDIUMBLOB For BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data

Learning Module on IM 201


59

LONGTEXT Holds a string with a maximum length of 4,294,967,295 characters

LONGBLOB For BLOBs (Binary Large OBjects). Holds up to 4,294,967,295 bytes of data

ENUM(val1, val2, A string object that can have only one value, chosen from a list of possible values. You
val3, ...) can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list,
a blank value will be inserted. The values are sorted in the order you enter them

SET(val1, val2, A string object that can have 0 or more values, chosen from a list of possible values.
val3, ...) You can list up to 64 values in a SET list

Numeric data types:

Data type Description

BIT(size) A bit-value type. The number of bits per value is specified in size. The size parameter
can hold a value from 1 to 64. The default value for size is 1.

TINYINT(size) A very small integer. Signed range is from -128 to 127. Unsigned range is from 0 to
255. The size parameter specifies the maximum display width (which is 255)

BOOL Zero is considered as false, nonzero values are considered as true.

Learning Module on IM 201


60

BOOLEAN Equal to BOOL

SMALLINT(size) A small integer. Signed range is from -32768 to 32767. Unsigned range is from 0 to
65535. The size parameter specifies the maximum display width (which is 255)

MEDIUMINT(size) A medium integer. Signed range is from -8388608 to 8388607. Unsigned range is from
0 to 16777215. The size parameter specifies the maximum display width (which is 255)

INT(size) A medium integer. Signed range is from -2147483648 to 2147483647. Unsigned range
is from 0 to 4294967295. The size parameter specifies the maximum display width
(which is 255)

INTEGER(size) Equal to INT(size)

BIGINT(size) A large integer. Signed range is from -9223372036854775808 to


9223372036854775807. Unsigned range is from 0 to 18446744073709551615.
The size parameter specifies the maximum display width (which is 255)

FLOAT(size, d) A floating point number. The total number of digits is specified in size. The number of
digits after the decimal point is specified in the d parameter. This syntax is deprecated
in MySQL 8.0.17, and it will be removed in future MySQL versions

Learning Module on IM 201


61

FLOAT(p) A floating point number. MySQL uses the p value to determine whether to use FLOAT
or DOUBLE for the resulting data type. If p is from 0 to 24, the data type becomes
FLOAT(). If p is from 25 to 53, the data type becomes DOUBLE()

DOUBLE(size, d) A normal-size floating point number. The total number of digits is specified in size. The
number of digits after the decimal point is specified in the d parameter

DOUBLE
PRECISION(size, d)

DECIMAL(size, d) An exact fixed-point number. The total number of digits is specified in size. The number
of digits after the decimal point is specified in the d parameter. The maximum number
for size is 65. The maximum number for d is 30. The default value for size is 10. The
default value for d is 0.

DEC(size, d) Equal to DECIMAL(size,d)

Note: All the numeric data types may have an extra option: UNSIGNED or ZEROFILL. If you add the
UNSIGNED option, MySQL disallows negative values for the column. If you add the ZEROFILL option,
MySQL automatically also adds the UNSIGNED attribute to the column.
Date and Time data types:

Data type Description

Learning Module on IM 201


62

DATE A date. Format: YYYY-MM-DD. The supported range is from '1000-


01-01' to '9999-12-31'

DATETIME(fsp) A date and time combination. Format: YYYY-MM-DD hh:mm:ss. The


supported range is from '1000-01-01 00:00:00' to '9999-12-31
23:59:59'. Adding DEFAULT and ON UPDATE in the column
definition to get automatic initialization and updating to the current
date and time

TIMESTAMP(fsp) A timestamp. TIMESTAMP values are stored as the number of


seconds since the Unix epoch ('1970-01-01 00:00:00' UTC). Format:
YYYY-MM-DD hh:mm:ss. The supported range is from '1970-01-01
00:00:01' UTC to '2038-01-09 03:14:07' UTC. Automatic initialization
and updating to the current date and time can be specified using
DEFAULT CURRENT_TIMESTAMP and ON UPDATE
CURRENT_TIMESTAMP in the column definition

TIME(fsp) A time. Format: hh:mm:ss. The supported range is from '-838:59:59' to


'838:59:59'

YEAR A year in four-digit format. Values allowed in four-digit format: 1901


to 2155, and 0000.
MySQL 8.0 does not support year in two-digit format.

Learning Module on IM 201


63

SQL Server Data Types


String data types:

Data type Description Max size Storage

char(n) Fixed width 8,000 characters Defined width


character string

varchar(n) Variable width 8,000 characters 2 bytes + number of chars


character string

varchar(max) Variable width 1,073,741,824 2 bytes + number of chars


character string characters

Text Variable width 2GB of text data 4 bytes + number of chars


character string

Nchar Fixed width Unicode 4,000 characters Defined width x 2


string

nvarchar Variable width 4,000 characters


Unicode string

Learning Module on IM 201


64

nvarchar(max) Variable width 536,870,912


Unicode string characters

Ntext Variable width 2GB of text data


Unicode string

binary(n) Fixed width binary 8,000 bytes


string

varbinary Variable width 8,000 bytes


binary string

varbinary(max) Variable width 2GB


binary string

Image Variable width 2GB


binary string

Numeric data types:

Data type Description Storage

Bit Integer that can be 0, 1, or NULL

Learning Module on IM 201


65

Tinyint Allows whole numbers from 0 to 255 1 byte

smallint Allows whole numbers between -32,768 and 32,767 2 bytes

Int Allows whole numbers between -2,147,483,648 and 2,147,483,647 4 bytes

Bigint Allows whole numbers between -9,223,372,036,854,775,808 and 8 bytes


9,223,372,036,854,775,807

5-17 bytes
decimal(p,s) Fixed precision and scale numbers.

Allows numbers from -10^38 +1 to 10^38 –1.

The p parameter indicates the maximum total number of digits that can
be stored (both to the left and to the right of the decimal point). p must
be a value from 1 to 38. Default is 18.

The s parameter indicates the maximum number of digits stored to the


right of the decimal point. s must be a value from 0 to p. Default value is
0

numeric(p,s) Fixed precision and scale numbers. 5-17 bytes

Allows numbers from -10^38 +1 to 10^38 –1.

The p parameter indicates the maximum total number of digits that can
be stored (both to the left and to the right of the decimal point). p must
be a value from 1 to 38. Default is 18.

Learning Module on IM 201


66

The s parameter indicates the maximum number of digits stored to the


right of the decimal point. s must be a value from 0 to p. Default value is
0

smallmoney Monetary data from -214,748.3648 to 214,748.3647 4 bytes

Money Monetary data from -922,337,203,685,477.5808 to 8 bytes


922,337,203,685,477.5807

float(n) Floating precision number data from -1.79E + 308 to 1.79E + 308. 4 or 8 bytes

The n parameter indicates whether the field should hold 4 or 8 bytes.


float(24) holds a 4-byte field and float(53) holds an 8-byte field. Default
value of n is 53.

Real Floating precision number data from -3.40E + 38 to 3.40E + 38 4 bytes

Date and Time data types:

Data type Description Storage

datetime From January 1, 1753 to December 31, 9999 with an 8 bytes


accuracy of 3.33 milliseconds

datetime2 From January 1, 0001 to December 31, 9999 with an 6-8 bytes
accuracy of 100 nanoseconds

Learning Module on IM 201


67

smalldatetime From January 1, 1900 to June 6, 2079 with an accuracy 4 bytes


of 1 minute

Date Store a date only. From January 1, 0001 to December 31, 3 bytes
9999

Time Store a time only to an accuracy of 100 nanoseconds 3-5 bytes

datetimeoffset The same as datetime2 with the addition of a time zone 8-10 bytes
offset

timestamp Stores a unique number that gets updated every time a


row gets created or modified. The timestamp value is
based upon an internal clock and does not correspond to
real time. Each table may have only one timestamp
variable

Other data types:

Data type Description

sql_variant Stores up to 8,000 bytes of data of various data types, except text, ntext, and
timestamp

Learning Module on IM 201


68

uniqueidentifier Stores a globally unique identifier (GUID)

Xml Stores XML formatted data. Maximum 2GB

Cursor Stores a reference to a cursor used for database operations

Table Stores a result-set for later processing

SQL DATABASE

The SQL CREATE DATABASE Statement


The CREATE DATABASE statement is used to create a new SQL database.
Syntax

CREATE DATABASE databasename;

CREATE DATABASE Example


The following SQL statement creates a database called "testDB":
Example

CREATE DATABASE testDB;

Learning Module on IM 201


69

Make sure you have admin privilege before creating any database. Once a database is created, you can check it
in the list of databases with the following SQL command: SHOW DATABASES; and SHOW tables; to display
all tables; the SQL USE statement is used to select any existing database in the SQL schema with the following
SQL command: USE databasename;

The SQL DROP DATABASE Statement


The DROP DATABASE statement is used to drop an existing SQL database.
Syntax

DROP DATABASE databasename;

Note: Be careful before dropping a database. Deleting a database will result in loss of complete information stored
in the database!
DROP DATABASE Example
The following SQL statement drops the existing database "testDB":
Example

DROP DATABASE testDB;

Tip: Make sure you have admin privilege before dropping any database. Once a database is dropped, you can
check it in the list of databases with the following SQL command: SHOW DATABASES;

The SQL BACKUP DATABASE Statement


The BACKUP DATABASE statement is used in SQL Server to create a full back up of an existing SQL database.
Syntax

BACKUP DATABASE databasename


TO DISK = 'filepath';

Learning Module on IM 201


70

The SQL BACKUP WITH DIFFERENTIAL Statement


A differential back up only backs up the parts of the database that have changed since the last full database backup.
Syntax

BACKUP DATABASE databasename


TO DISK = 'filepath'
WITH DIFFERENTIAL;

BACKUP DATABASE Example


The following SQL statement creates a full back up of the existing database "testDB" to the D disk:
Example

BACKUP DATABASE testDB


TO DISK = 'D:\backups\testDB.bak';

Tip: Always back up the database to a different drive than the actual database. Then, if you get a disk crash, you
will not lose your backup file along with the database.
BACKUP WITH DIFFERENTIAL Example
The following SQL statement creates a differential back up of the database "testDB":
Example

BACKUP DATABASE testDB


TO DISK = 'D:\backups\testDB.bak'
WITH DIFFERENTIAL;

Tip: A differential back up reduces the back up time (since only the changes are backed up).

Learning Module on IM 201


71

The SQL CREATE TABLE Statement


The CREATE TABLE statement is used to create a new table in a database.

Syntax

CREATE TABLE table_name (


column1 datatype,
column2 datatype,
column3 datatype,
....
);

The column parameters specify the names of the columns of the table.
The datatype parameter specifies the type of data the column can hold (e.g. varchar, integer, date, etc.).
Tip: For an overview of the available data types, see the Data Types Reference.
SQL CREATE TABLE Example
The following example creates a table called "Persons" that contains five columns: PersonID, LastName,
FirstName, Address, and City:
Example

CREATE TABLE Persons (


PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)

Learning Module on IM 201


72

);

The PersonID column is of type int and will hold an integer.

The LastName, FirstName, Address, and City columns are of type varchar and will hold characters, and the
maximum length for these fields is 255 characters.

The empty "Persons" table will now look like this:

Tip: The empty "Persons" table can now be filled with data with the SQL INSERT INTO statement.

Create Table Using Another Table


A copy of an existing table can also be created using CREATE TABLE.
The new table gets the same column definitions. All columns or specific columns can be selected.
If you create a new table using an existing table, the new table will be filled with the existing values from the old
table.
Syntax

CREATE TABLE new_table_name AS


SELECT column1, column2,...
FROM existing_table_name
WHERE ....;

The following SQL creates a new table called "TestTables" (which is a copy of the "Customers" table):
Example

Learning Module on IM 201


73

CREATE TABLE TestTable AS


SELECT customername, contactname
FROM customers;

The SQL DROP TABLE Statement


The DROP TABLE statement is used to drop an existing table in a database.
Syntax

DROP TABLE table_name;

Note: Be careful before dropping a table. Deleting a table will result in loss of complete information stored in the
table!
SQL DROP TABLE Example
The following SQL statement drops the existing table "Shippers":
Example

DROP TABLE Shippers;

SQL TRUNCATE TABLE


The TRUNCATE TABLE statement is used to delete the data inside a table, but not the table itself.
Syntax

TRUNCATE TABLE table_name;

SQL ALTER TABLE Statement


The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

Learning Module on IM 201


74

The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
ALTER TABLE - ADD Column
To add a column in a table, use the following syntax:

ALTER TABLE table_name


ADD column_name datatype;

The following SQL adds an "Email" column to the "Customers" table:


Example

ALTER TABLE Customers


ADD Email varchar(255);

ALTER TABLE - DROP COLUMN


To delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a
column):

ALTER TABLE table_name


DROP COLUMN column_name;

The following SQL deletes the "Email" column from the "Customers" table:
Example

ALTER TABLE Customers


DROP COLUMN Email;

Learning Module on IM 201


75

M1:L3 EXERCISE.
a. Write the correct SQL statement to create a new database called ccc;

b. SQL statement creates a full back up of the existing database "ccc" to file path “D:\backups\” with file name
“cccdb”:

c. SQL statement to use database ccc.

d. Write the correct SQL statement to create a new table called student. With the following columns and
datatypes:
studentID int,
LastName varchar(255)
FirstName varchar(255)
Address varchar(255)

e. SQL statement to add "course" column with datatype and size varchar(150) to the "student" table:

f. SQL statement to drop "course" column in "student" table:

Learning Module on IM 201


76

g. SQL statement to drop the existing database "ccc".

h. SQL statement to show all databases.

M1:L3 Application
Solve the following problem based on the given data below of Company ABC; note that your answer should be
reflected to the below info:
Database name: abcDB
Table name: worker

1. SQL statement to create database for company ABC.

2. SQL statement to show all databases;

3. SQL statement to use your newly created database for company ABC.

Learning Module on IM 201


77

4. SQL statement to create the database table of Company ABC based on the given table with the following
datatype and size; note that column name should not be changed based on the table above.

Worker id – int(10),
First name- char(25),
Last name – char(25),
Salary – int(15),
Joining date - datetime,
Department – char(25)
Note: datetime do not have size

Learning Module on IM 201


78

Summary of the Lesson:


1. In this chapter we introduced the capabilities of SQL.
2. Discussed the installation process of XAMPP localhost server to run SQL commands.
3. Discussed the operators and datatypes that can be used and the Database SQL statements.

Learning Module on IM 201


79

M1:L3 Enrichment Activity


Solve the following problem based on the given data below of Company DEF; note that your answer should be
reflected to the below info:
Database name: defDB
Table name: title

1. SQL statement to create database for company DEF.

2. SQL statement to show all databases;

3. SQL statement to use your newly created database for company DEF.

4. SQL statement to create the database table of Company DEF based on the given table with the following
datatype and size; note that column name should not be changed based on the table above.

Learning Module on IM 201


80

Worker reference id – int(10),


Worker title- char(25),
Affected from - datetime
Note: datetime do not have size

Learning Module on IM 201


81

M1 Assessment:
I. Identify the below responsibilities whether it is for database designer or database administrator. Write
DBD for database administrator otherwise DBA for database designer on the space provided before each
number.
__________________1. Conducting data backups
__________________2. Assessing database performance
__________________3. Modifying database structure if needed
__________________4. Restoring lost data
__________________5. communicate with all prospective database users
__________________6. Debugging programs or installing patches
__________________7. authorizing access to the database
__________________8. acquiring software
__________________9. purchasing hardware resources as needed
__________________10. responsible for identifying the data to be stored in the database
__________________11. choosing appropriate structures to represent and store this data
__________________12. implement the database design
__________________13. tune database performance
__________________14. install the database server software
__________________15. plan how the logical storage structure of the database will affect system performance

II. Create the schema from the below two views derived from the database. Write your answer on the space
provided.

Learning Module on IM 201


82

III. Write the SQL statement for the below problems on the lines provided.
1. Write the correct SQL statement to create a new database called teashop;
__________________________________________________________________________________________
__________________________________________________________________
2. SQL statement creates a full back up of the existing database " teashop " to file path “D:\backup\” with file
name “teashop_db”:
__________________________________________________________________________________________
__________________________________________________________________
3. SQL statement to use database teashop.

Learning Module on IM 201


83

__________________________________________________________________________________________
__________________________________________________________________
4. Write the correct SQL statement to create a new table called cust. With the following columns and datatypes:
custID int(10),
custLastName varchar(255)
custFirstName varchar(255)
custAddress varchar(255)
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
____________________________________________________________________________________
5. SQL statement to add "order_type" column with datatype and size varchar(250) to the "student" table:
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________
6. SQL statement to drop "course" column in "student" table:
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________
7. SQL statement to drop the existing database "teashop".
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________
8. SQL statement to show all databases.
__________________________________________________________________________________________
__________________________________________________________________________________________

Learning Module on IM 201


84

I. Course Code IM 201


II. Course Title Fundamentals of Database Systems
III. Module Number 2
IV. Module Title SQL Commands and Relational Model
V. Overview of the Module This module will discuss SQL. SQL is a standard language for storing,
manipulating and retrieving data in databases. It is a standard language for
accessing and manipulating databases. It will also tackle the relational database.
The relational data model was first introduced by Ted Codd of IBM Research in
1970 in a classic paper (Codd, 1970), and 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. In this chapter we discuss the basic characteristics of the model.
VI. Module Outcomes Once you have mastered the material, you will be able to: identify basic
commands of SQL; execute basic commands of SQL; apply basic commands of
SQL; identify the different database models; understand the concept relational
model; and identify the different relational keys that are being used in databases.

Learning Module on IM 201


85

Lesson1. SQL Commands


SQL is a standard language for storing, manipulating and retrieving data in databases. It is a standard language
for accessing and manipulating databases.
Lesson Objectives:
Once you have mastered the material in this chapter you will be able to:

1. Identify basic commands of SQL.


2. Execute basic commands of SQL.
3. Apply basic commands of SQL.

Discussion:
What is SQL?
SQL stands for Structured Query Language
SQL lets you access and manipulate databases
SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International
Organization for Standardization (ISO) in 1987
What Can SQL do?
▪ SQL can execute queries against a database
▪ SQL can retrieve data from a database
▪ SQL can insert records in a database
▪ SQL can update records in a database
▪ SQL can delete records from a database
▪ SQL can create new databases
▪ SQL can create new tables in a database
▪ SQL can create stored procedures in a database
▪ SQL can create views in a database
▪ SQL can set permissions on tables, procedures, and views

SQL is a Standard - BUT....


Although SQL is an ANSI/ISO standard, there are different versions of the SQL language.
However, to be compliant with the ANSI standard, they all support at least the major commands (such as
SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.

Learning Module on IM 201


86

Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL
standard!
Using SQL in Your Web Site
To build a web site that shows data from a database, you will need:
▪ An RDBMS database program (i.e. MS Access, SQL Server, MySQL)
▪ To use a server-side scripting language, like PHP or ASP
▪ To use SQL to get the data you want
▪ To use HTML / CSS to style the page
RDBMS
RDBMS stands for Relational Database Management System.
RDBMS is the basis for SQL, and for all modern database systems such as MS SQL Server, IBM DB2, Oracle,
MySQL, and Microsoft Access.
The data in RDBMS is stored in database objects called tables. A table is a collection of related data entries and
it consists of columns and rows.
Look at the "Customers" table:
Example

SELECT * FROM Customers;

Every table is broken up into smaller entities called fields. The fields in the Customers table consist of
CustomerID, CustomerName, ContactName, Address, City, PostalCode and Country. A field is a column in a
table that is designed to maintain specific information about every record in the table.
A record, also called a row, is each individual entry that exists in a table. For example, there are 91 records in the
above Customers table. A record is a horizontal entity in a table.
A column is a vertical entity in a table that contains all information associated with a specific field in a table.
SQL Syntax
Database Tables
A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or
"Orders"). Tables contain records (rows) with data.
Below is a selection from the "Customers" table:

Learning Module on IM 201


87

The table above contains five records (one for each customer) and seven columns (CustomerID, CustomerName,
ContactName, Address, City, PostalCode, and Country).

SQL Statements
Most of the actions you need to perform on a database are done with SQL statements.
The following SQL statement selects all the records in the "Customers" table:
Example

SELECT * FROM Customers;

Keep in Mind That...


SQL keywords are NOT case sensitive: select is the same as SELECT

Semicolon after SQL Statements?


Some database systems require a semicolon at the end of each SQL statement.
Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL
statement to be executed in the same call to the server.

Some of The Most Important SQL Commands

Learning Module on IM 201


88

▪ SELECT - extracts data from a database


▪ UPDATE - updates data in a database
▪ DELETE - deletes data from a database
▪ INSERT INTO - inserts new data into a database
▪ CREATE DATABASE - creates a new database
▪ ALTER DATABASE - modifies a database
▪ CREATE TABLE - creates a new table
▪ ALTER TABLE - modifies a table
▪ DROP TABLE - deletes a table
▪ CREATE INDEX - creates an index (search key)
▪ DROP INDEX - deletes an index

The SQL INSERT INTO Statement


The INSERT INTO statement is used to insert new records in a table.
INSERT INTO Syntax
It is possible to write the INSERT INTO statement in two ways.
The first way specifies both the column names and the values to be inserted:

INSERT INTO table_name (column1, column2, column3, ...)


VALUES (value1, value2, value3, ...);

If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL
query. However, make sure the order of the values is in the same order as the columns in the table. The INSERT
INTO syntax would be as follows:

INSERT INTO table_name


VALUES (value1, value2, value3, ...);

Demo Database
Below is a selection from the "Customers" table in the Northwind sample database:

Learning Module on IM 201


89

INSERT INTO Example


The following SQL statement inserts a new record in the "Customers" table:
Example

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)


VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

Insert Data Only in Specified Columns


It is also possible to only insert data in specific columns.
The following SQL statement will insert a new record, but only insert data in the "CustomerName", "City", and
"Country" columns (CustomerID will be updated automatically):
Example

INSERT INTO Customers (CustomerName, City, Country)


VALUES ('Cardinal', 'Stavanger', 'Norway');

The SQL SELECT Statement


The SELECT statement is used to select data from a database.
The data returned is stored in a result table, called the result-set.
SELECT Syntax

Learning Module on IM 201


90

SELECT column1, column2, ...


FROM table_name;

Here, column1, column2, ... are the field names of the table you want to select data from. If you want to select all
the fields available in the table, use the following syntax:

SELECT * FROM table_name;

Demo Database
Below is a selection from the "Customers" table in the Northwind sample database:

SELECT Column Example


The following SQL statement selects the "CustomerName" and "City" columns from the "Customers" table:
Example

SELECT CustomerName, City FROM Customers;

Learning Module on IM 201


91

SELECT * Example
The following SQL statement selects all the columns from the "Customers" table:
Example

SELECT * FROM Customers;

The SQL SELECT DISTINCT Statement


The SELECT DISTINCT statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different
(distinct) values.

SELECT DISTINCT Syntax

Learning Module on IM 201


92

SELECT DISTINCT column1, column2, ...


FROM table_name;

Demo Database
Below is a selection from the "Customers" table in the Northwind sample database:

SELECT Example Without DISTINCT


The following SQL statement selects ALL (including the duplicates) values from the "Country" column in the
"Customers" table:
Example
SELECT Country FROM Customers;

SELECT DISTINCT Examples

Learning Module on IM 201


93

The following SQL statement selects only the DISTINCT values from the "Country" column in the
"Customers" table:
Example

SELECT DISTINCT Country FROM Customers;

The following SQL statement lists the number of different (distinct) customer countries:
Example

SELECT COUNT(DISTINCT Country) FROM Customers;

The SQL WHERE Clause


The WHERE clause is used to filter records.
The WHERE clause is used to extract only those records that fulfill a specified condition.

WHERE Syntax

SELECT column1, column2, ...


FROM table_name
WHERE condition;

Note: The WHERE clause is not only used in SELECT statement, it is also used in UPDATE, DELETE statement,
etc.!

Learning Module on IM 201


94

WHERE Clause Example


The following SQL statement selects all the customers from the country "Mexico", in the "Customers" table:
Example

SELECT * FROM Customers


WHERE Country='Mexico';

Text Fields vs. Numeric Fields


SQL requires single quotes around text values (most database systems will also allow double quotes).
However, numeric fields should not be enclosed in quotes:
Example

SELECT * FROM Customers


WHERE CustomerID=1;

Operators in The WHERE Clause


The following operators can be used in the WHERE clause:
Operator Description
= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal. Note: In some versions of SQL this operator may be written as !=
BETWEEN Between a certain range
LIKE Search for a pattern

Learning Module on IM 201


95

IN To specify multiple possible values for a column

The SQL AND, OR and NOT Operators


The WHERE clause can be combined with AND, OR, and NOT operators.
The AND and OR operators are used to filter records based on more than one condition:
The AND operator displays a record if all the conditions separated by AND are TRUE.
The OR operator displays a record if any of the conditions separated by OR is TRUE.
The NOT operator displays a record if the condition(s) is NOT TRUE.

AND Syntax

SELECT column1, column2, ...


FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;

OR Syntax

SELECT column1, column2, ...


FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;

NOT Syntax

SELECT column1, column2, ...


FROM table_name
WHERE NOT condition;

Learning Module on IM 201


96

AND Example
The following SQL statement selects all fields from "Customers" where country is "Germany" AND city is
"Berlin":
Example

SELECT * FROM Customers


WHERE Country='Germany' AND City='Berlin';

OR Example
The following SQL statement selects all fields from "Customers" where city is "Berlin" OR "München":
Example

SELECT * FROM Customers

Learning Module on IM 201


97

WHERE City='Berlin' OR City='München';

The following SQL statement selects all fields from "Customers" where country is "Germany" OR "Spain":
Example

SELECT * FROM Customers


WHERE Country='Germany' OR Country='Spain';

NOT Example
The following SQL statement selects all fields from "Customers" where country is NOT "Germany":
Example
SELECT * FROM Customers
WHERE NOT Country='Germany';

Combining AND, OR and NOT


You can also combine the AND, OR and NOT operators.
The following SQL statement selects all fields from "Customers" where country is "Germany" AND city must be
"Berlin" OR "München" (use parenthesis to form complex expressions):
Example

SELECT * FROM Customers


WHERE Country='Germany' AND (City='Berlin' OR City='München');

The following SQL statement selects all fields from "Customers" where country is NOT "Germany" and NOT
"USA":
Example

Learning Module on IM 201


98

SELECT * FROM Customers


WHERE NOT Country='Germany' AND NOT Country='USA';

The SQL ORDER BY Keyword


The ORDER BY keyword is used to sort the result-set in ascending or descending order.
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order,
use the DESC keyword.
ORDER BY Syntax

SELECT column1, column2, ...


FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

Demo Database
Below is a selection from the "Customers" table in the Northwind sample database:

ORDER BY Example
The following SQL statement selects all customers from the "Customers" table, sorted by the "Country" column:

Learning Module on IM 201


99

Example

SELECT * FROM Customers


ORDER BY Country;

ORDER BY DESC Example


The following SQL statement selects all customers from the "Customers" table, sorted DESCENDING by the
"Country" column:
Example
SELECT * FROM Customers
ORDER BY Country DESC;

ORDER BY Several Columns Example


The following SQL statement selects all customers from the "Customers" table, sorted by the "Country" and the
"CustomerName" column. This means that it orders by Country, but if some rows have the same Country, it orders
them by CustomerName:
Example

SELECT * FROM Customers


ORDER BY Country, CustomerName;

ORDER BY Several Columns Example


The following SQL statement selects all customers from the "Customers" table, sorted ascending by the "Country"
and descending by the "CustomerName" column:
Example

SELECT * FROM Customers


ORDER BY Country ASC, CustomerName DESC;

Learning Module on IM 201


100

The SQL UPDATE Statement


The UPDATE statement is used to modify the existing records in a table.
UPDATE Syntax

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Note: Be careful when updating records in a table! Notice the WHERE clause in the UPDATE statement. The
WHERE clause specifies which record(s) that should be updated. If you omit the WHERE clause, all records in
the table will be updated!

Demo Database
Below is a selection from the "Customers" table in the Northwind sample database:

UPDATE Table
The following SQL statement updates the first customer (CustomerID = 1) with a new contact person and a new
city.

Learning Module on IM 201


101

Example

UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;

The selection from the "Customers" table will now look like this:

UPDATE Multiple Records


It is the WHERE clause that determines how many records will be updated.

The following SQL statement will update the contactname to "Juan" for all records where country is "Mexico":
Example

UPDATE Customers
SET ContactName='Juan'
WHERE Country='Mexico';

Learning Module on IM 201


102

The selection from the "Customers" table will now look like this:

Update Warning!
Be careful when updating records. If you omit the WHERE clause, ALL records will be updated!

Example

UPDATE Customers
SET ContactName='Juan';

The selection from the "Customers" table will now look like this:

Learning Module on IM 201


103

The SQL DELETE Statement


The DELETE statement is used to delete existing records in a table.
DELETE Syntax

DELETE FROM table_name WHERE condition;

Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The
WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause, all records in the
table will be deleted!
Demo Database
Below is a selection from the "Customers" table in the Northwind sample database:

Learning Module on IM 201


104

SQL DELETE Example


The following SQL statement deletes the customer "Alfreds Futterkiste" from the "Customers" table:
Example

DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';

The "Customers" table will now look like this:

Delete All Records

Learning Module on IM 201


105

It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes,
and indexes will be intact:

DELETE FROM table_name;

The following SQL statement deletes all rows in the "Customers" table, without deleting the table:

Example

DELETE FROM Customers;

The SQL MIN() and MAX() Functions


The MIN() function returns the smallest value of the selected column.
The MAX() function returns the largest value of the selected column.

MIN() Syntax

SELECT MIN(column_name)
FROM table_name
WHERE condition;

MAX() Syntax

SELECT MAX(column_name)
FROM table_name
WHERE condition;

Learning Module on IM 201


106

Demo Database
Below is a selection from the "Products" table in the Northwind sample database:

MIN() Example
The following SQL statement finds the price of the cheapest product:
Example

SELECT MIN(Price) AS SmallestPrice


FROM Products;

MAX() Example
The following SQL statement finds the price of the most expensive product:
Example

SELECT MAX(Price) AS LargestPrice


FROM Products;

The SQL COUNT(), AVG() and SUM() Functions


The COUNT() function returns the number of rows that matches a specified criterion.
The AVG() function returns the average value of a numeric column.
The SUM() function returns the total sum of a numeric column.

Learning Module on IM 201


107

COUNT() Syntax

SELECT COUNT(column_name)
FROM table_name
WHERE condition;

AVG() Syntax

SELECT AVG(column_name)
FROM table_name
WHERE condition;

SUM() Syntax

SELECT SUM(column_name)
FROM table_name
WHERE condition;

Demo Database
Below is a selection from the "Products" table in the Northwind sample database:

Learning Module on IM 201


108

COUNT() Example
The following SQL statement finds the number of products:
Example

SELECT COUNT(ProductID)
FROM Products;

Note: NULL values are not counted.

AVG() Example
The following SQL statement finds the average price of all products:
Example

SELECT AVG(Price)
FROM Products;

Note: NULL values are ignored.

Demo Database
Below is a selection from the "OrderDetails" table in the Northwind sample database:

Learning Module on IM 201


109

SUM() Example
The following SQL statement finds the sum of the "Quantity" fields in the "OrderDetails" table:
Example

SELECT SUM(Quantity)
FROM OrderDetails;

Note: NULL values are ignored.

The SQL LIKE Operator


The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
There are two wildcards often used in conjunction with the LIKE operator:

% - The percent sign represents zero, one, or multiple characters


_ - The underscore represents a single character
Note: MS Access uses an asterisk (*) instead of the percent sign (%), and a question mark (?) instead of the
underscore (_).
The percent sign and the underscore can also be used in combinations!

LIKE Syntax

Learning Module on IM 201


110

SELECT column1, column2, ...


FROM table_name
WHERE column LIKE pattern;

Tip: You can also combine any number of conditions using AND or OR operators.
Here are some examples showing different LIKE operators with '%' and '_' wildcards:

Demo Database
The table below shows the complete "Customers" table from the Northwind sample database:

Learning Module on IM 201


111

SQL LIKE Examples


The following SQL statement selects all customers with a CustomerName starting with "a":
Example

SELECT * FROM Customers


WHERE CustomerName LIKE 'a%';

The following SQL statement selects all customers with a CustomerName ending with "a":
Example

SELECT * FROM Customers


WHERE CustomerName LIKE '%a';

The following SQL statement selects all customers with a CustomerName that have "or" in any position:

Learning Module on IM 201


112

Example

SELECT * FROM Customers


WHERE CustomerName LIKE '%or%';

The following SQL statement selects all customers with a CustomerName that have "r" in the second position:
Example

SELECT * FROM Customers


WHERE CustomerName LIKE '_r%';

The following SQL statement selects all customers with a CustomerName that starts with "a" and are at least 3
characters in length:
Example

SELECT * FROM Customers


WHERE CustomerName LIKE 'a__%';

The following SQL statement selects all customers with a ContactName that starts with "a" and ends with "o":
Example

SELECT * FROM Customers


WHERE ContactName LIKE 'a%o';

The following SQL statement selects all customers with a CustomerName that does NOT start with "a":
Example

Learning Module on IM 201


113

SELECT * FROM Customers


WHERE CustomerName NOT LIKE 'a%';

Learning Module on IM 201


114

M2:L1 EXERCISE.
Write false if the statement is true otherwise true. Write your answer on the space provided before each number.
__________________a. The WHERE clause is used to extract only those records that fulfill a specified condition.
__________________b. SQL requires single quotes around text values (most database systems will also allow
double quotes).
__________________c. The AND operator displays a record if all the conditions separated by AND is TRUE.
__________________d. The OR operator displays a record if any of the conditions separated by OR is TRUE.
__________________e. The NOT operator displays a record if the condition(s) is NOT TRUE.
__________________f. The COUNT() function returns the number of rows that matches a specified criteria.
__________________g. The AVG() function returns the average value of a numeric column.
__________________h. The SUM() function returns the total sum of a numeric column.
__________________i. If you are adding values for all the columns of the table, you do not need to specify the
column names in the SQL query.
__________________j. The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE
clause, all records in the table will be deleted.

M2:L1 Application
Create the SQL command for the below problems; use the table below for the instance of the database.
DB Name: Company_ABC
DB Table: Employee
EMP_id EMP_name EMP_sex EMP_add EMP_byear EMP_hdate EMP_basicpay
San Pablo
1 John M City 1990 2009 25000
San Pablo
2 Eve F City 1994 2011 24000
Calamba
3 Matt M City 1992 2005 30000
Calamba
4 Mary F City 1987 2002 35000

Learning Module on IM 201


115

1. SQL command to create database Company_ABC.


__________________________________________________________________________________________
________________________________________________________________________________
2. SQL command to create table Employee.
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
____________________________________________________________
3. SQL command to insert employee 1.
__________________________________________________________________________________________
________________________________________________________________________________
4. SQL command to insert employee 2.
__________________________________________________________________________________________
________________________________________________________________________________
5. SQL command to insert employee 3.
__________________________________________________________________________________________
________________________________________________________________________________
6. SQL command to insert employee 4.
__________________________________________________________________________________________
________________________________________________________________________________
7. SQL command to get the sum of basic pay of all employees.
__________________________________________________________________________________________
________________________________________________________________________________
8. SQL command to count all male employees residing at San Pablo City.
__________________________________________________________________________________________
________________________________________________________________________________

Learning Module on IM 201


116

Summary of the Lesson:


1. SQL lets you access and manipulate databases
2. What Can SQL do?
o SQL can execute queries against a database
o SQL can retrieve data from a database
o SQL can insert records in a database
o SQL can update records in a database
o SQL can delete records from a database
o SQL can create new databases
o SQL can create new tables in a database
o SQL can create stored procedures in a database
o SQL can create views in a database
o SQL can set permissions on tables, procedures, and views

3. SQL is a Standard however, to be compliant with the ANSI standard, they all support at least the major
commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner. Most of the SQL
database programs also have their own proprietary extensions in addition to the SQL standard.

Learning Module on IM 201


117

M2:L1 Enrichment Activity:


Use the above table and info in application to solve the below problems.
a. SQL command to count all female employees residing at Calamba City.
__________________________________________________________________________________________
________________________________________________________________________________
b. SQL command to get the age of employee 2.
__________________________________________________________________________________________
________________________________________________________________________________
c. SQL command to count employees that were hired from 2000 to 2010 and currently residing at San Pablo City.
__________________________________________________________________________________________
________________________________________________________________________________
d. SQL command to show all databases.
__________________________________________________________________________________________
________________________________________________________________________________
e. SQL command to show all tables.
__________________________________________________________________________________________
________________________________________________________________________________

Learning Module on IM 201


118

Lesson 2. Relational Model


The relational data model was first introduced by Ted Codd of IBM Research in 1970 in a classic paper (Codd,
1970), and 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. In this chapter we discuss the basic
characteristics of the model.
Lesson Objectives:
Once you have mastered the material in this chapter you will be able to:

1. identify the different database models;


2. Understand the concept relational model;
3. identify the different relational keys that are being used in databases.

Discussion:
DBMS Database Models
A Database model defines the logical design and structure of a database and defines how data will be stored,
accessed and updated in a database management system. While the Relational Model is the most widely used
database model, there are other models too:
• Hierarchical Model
• Network Model
• Entity-relationship Model
• Relational Model
Hierarchical Model
This database model organizes data into a tree-like-structure, with a single root, to which all the other data is
linked. The hierarchy starts from the Root data, and expands like a tree, adding child nodes to the parent nodes.
In this model, a child node will only have a single parent node. This model efficiently describes many real-world
relationships like index of a book, recipes etc.
In hierarchical model, data is organized into tree-like structure with one one-to-many relationship between two
different types of data, for example, one department can have many courses, many professors and of course many
students.

Learning Module on IM 201


119

Network Model
This is an extension of the Hierarchical model. In this model data is organized more like a graph, and are allowed
to have more than one parent node. In this database model data is more related as more relationships are
established in this database model. Also, as the data is more related, hence accessing the data is also easier and
fast. This database model was used to map many-to-many data relationships. This was the most widely used
database model, before Relational Model was introduced.

Entity-relationship Model
In this database model, relationships are created by dividing object of interest into entity and its characteristics
into attributes.
Different entities are related using relationships.
E-R Models are defined to represent the relationships into pictorial form to make it easier for different
stakeholders to understand.
This model is good to design a database, which can then be turned into tables in relational model.

Learning Module on IM 201


120

Let's take an example, if we have to design a School Database, then Student will be an entity with attributes name,
age, address etc. As Address is generally complex, it can be another entity with attributes street name, pincode,
city etc, and there will be a relationship between them.

Relational Model
In this model, data is organized in two-dimensional tables and the relationship is maintained by storing a common
field. This model was introduced by Codd in 1970, and since then it has been the most widely used database
model, in fact, we can say the only database model used around the world. The basic structure of data in the
relational model is tables. All the information related to a particular type is stored in rows of that table. Hence,
tables are also known as relations in relational model. Relationships can also be of different types.

What is Relational Model?


RELATIONAL MODEL (RM) represents the database as a collection of relations. A relation is nothing but a
table of values. Every row in the table represents a collection of related data values. These rows in the table denote
a real-world entity or relationship.

Learning Module on IM 201


121

The table name and column names are helpful to interpret the meaning of values in each row. The data are
represented as a set of relations. In the relational model, data are stored as tables. However, the physical storage
of the data is independent of the way the data are logically organized.
Some popular Relational Database management systems are:

DB2 and Informix Dynamic Server - IBM


Oracle and RDB – Oracle
SQL Server and Access – Microsoft
Relational Model Concepts
Attribute - Each column in a Table. Attributes are the properties which define a relation. e.g., Student_Rollno,
NAME,etc.
Tables – In the Relational model the, relations are saved in the table format. It is stored along with its entities. A
table has two properties rows and columns. Rows represent records and columns represent attributes.
Tuple – It is nothing but a single row of a table, which contains a single record.
Relation Schema – A relation schema represents the name of the relation with its attributes.
Degree – The total number of attributes which in the relation is called the degree of the relation.
Cardinality – Total number of rows present in the Table.
Column – The column represents the set of values for a specific attribute.
Relation instance – Relation instance is a finite set of tuples in the RDBMS system. Relation instances never
have duplicate tuples.
Relation key - Every row has one, two or multiple attributes, which is called relation key.
Attribute domain – Every attribute has some pre-defined value and scope which is known as attribute domain.

Learning Module on IM 201


122

Relational Integrity constraints


Relational Integrity constraints is referred to conditions which must be present for a valid relation. These integrity
constraints are derived from the rules in the mini-world that the database represents.
There are many types of integrity constraints. Constraints on the Relational database management system is
mostly divided into three main categories are:
Domain constraints
Key constraints
Referential integrity constraints

Domain Constraints
Domain constraints can be violated if an attribute value is not appearing in the corresponding domain or it is not
of the appropriate data type.

Domain constraints specify that within each tuple, and the value of each attribute must be unique. This is specified
as data types which include standard data types integers, real numbers, characters, Booleans, variable length
strings, etc.
Key constraints
An attribute that can uniquely identify a tuple in a relation is called the key of the table. The value of the attribute
for different tuples in the relation has to be unique.
Example:

Learning Module on IM 201


123

In the given table, CustomerID is a key attribute of Customer Table. It is most likely to have a single key for one
customer, CustomerID =1 is only for the CustomerName =" Google".

Referential integrity constraints


Referential integrity constraints are based on the concept of Foreign Keys. A foreign key is an important attribute
of a relation which should be referred to in other relationships. Referential integrity constraint state happens where
relation refers to a key attribute of a different or same relation. However, that key element must exist in the
table.

In the above example, we have 2 relations, Customer and Billing.


Tuple for CustomerID =1 is referenced twice in the relation Billing. So we know CustomerName=Google has
billing amount $300.
Operations in Relational Model
Four basic update operations performed on relational database model are

Learning Module on IM 201


124

Insert, update, delete and select.


• Insert is used to insert data into the relation
• Delete is used to delete tuples from the table.
• Modify allows you to change the values of some attributes in existing tuples.
• Select allows you to choose a specific range of data.
Whenever one of these operations are applied, integrity constraints specified on the relational database schema
must never be violated.
Insert Operation
The insert operation gives values of the attribute for a new tuple which should be inserted into a relation.

Update Operation
You can see that in the below-given relation table CustomerName= 'Apple' is updated from Inactive to Active.

Delete Operation
To specify deletion, a condition on the attributes of the relation selects the tuple to be deleted.

In the above-given example, CustomerName= "Apple" is deleted from the table.

The Delete operation could violate referential integrity if the tuple which is deleted is referenced by foreign keys
from other tuples in the same database.

Learning Module on IM 201


125

Select Operation

In the above-given example, CustomerName="Amazon" is selected.


Best Practices for creating a Relational Model
• Data need to be represented as a collection of relations
• Each relation should be depicted clearly in the table
• Rows should contain data about instances of an entity
• Columns must contain data about attributes of the entity
• Cells of the table should hold a single value
• Each column should be given a unique name
• No two rows can be identical
• The values of an attribute should be from the same domain
Advantages of using Relational model
• Simplicity: A relational data model is simpler than the hierarchical and network model.
• Structural Independence: The relational database is only concerned with data and not with a structure. This
can improve the performance of the model.
• Easy to use: The relational model is easy as tables consisting of rows and columns is quite natural and simple
to understand
• Query capability: It makes possible for a high-level query language like SQL to avoid complex database
navigation.
• Data independence: The structure of a database can be changed without having to change any application.
• Scalable: Regarding a number of records, or rows, and the number of fields, a database should be enlarged to
enhance its usability.
Disadvantages of using Relational model
• Few relational databases have limits on field lengths which can't be exceeded.
• Relational databases can sometimes become complex as the amount of data grows, and the relations between
pieces of data become more complicated.
• Complex relational database systems may lead to isolated databases where the information cannot be shared
from one system to another.
What is Relational Algebra?
Every database management system must define a query language to allow users to access the data stored in the
database. Relational Algebra is a procedural query language used to query the database tables to access data in
different ways.

Learning Module on IM 201


126

In relational algebra, input is a relation(table from which data has to be accessed) and output is also a relation(a
temporary table holding the data asked for by the user).

Relational Algebra works on the whole table at once, so we do not have to use loops etc to iterate over all the
rows(tuples) of data one by one. All we have to do is specify the table name from which we need the data, and in
a single line of command, relational algebra will traverse the entire given table to fetch data for you.
The primary operations that we can perform using relational algebra are:
• Select
• Project
• Union
• Set Difference
• Cartesian product
• Rename
Select Operation (σ)
This is used to fetch rows(tuples) from table(relation) which satisfies a given condition.
Syntax: σp(r)
Where, σ represents the Select Predicate, r is the name of relation(table name in which you want to look for data),
and p is the prepositional logic, where we specify the conditions that must be satisfied by the data. In prepositional
logic, one can use unary and binary operators like =, <, > etc, to specify the conditions.
Let's take an example of the Student table we specified above in the Introduction of relational algebra, and fetch
data for students with age more than 17.
σage > 17 (Student)
This will fetch the tuples(rows) from table Student, for which age will be greater than 17.

Learning Module on IM 201


127

You can also use, and, or etc operators, to specify two conditions, for example,
σage > 17 and gender = 'Male' (Student)
This will return tuples(rows) from table Student with information of male students, of age more than 17.(Consider
the Student table has an attribute Gender too.)
Project Operation (∏)
Project operation is used to project only a certain set of attributes of a relation. In simple words, If you want to
see only the names all of the students in the Student table, then you can use Project Operation.
It will only project or show the columns or attributes asked for, and will also remove duplicate data from the
columns.
Syntax: ∏A1, A2...(r)
where A1, A2 etc are attribute names(column names).
For example,
∏Name, Age(Student)
Above statement will show us only the Name and Age columns for all the rows of data in Student table.
Union Operation (∪)
This operation is used to fetch data from two relations(tables) or temporary relation(result of another operation).
For this operation to work, the relations(tables) specified should have same number of attributes(columns) and
same attribute domain. Also the duplicate tuples are automatically eliminated from the result.
Syntax: A ∪ B
where A and B are relations.
For example, if we have two tables RegularClass and ExtraClass, both have a column student to save name of
student, then,
∏Student(RegularClass) ∪ ∏Student(ExtraClass)
Above operation will give us name of Students who are attending both regular classes and extra classes,
eliminating repetition.
Set Difference (-)
This operation is used to find data present in one relation and not present in the second relation. This operation is
also applicable on two relations, just like Union operation.
Syntax: A - B

Learning Module on IM 201


128

where A and B are relations.


For example, if we want to find name of students who attend the regular class but not the extra class, then, we
can use the below operation:
∏Student(RegularClass) - ∏Student(ExtraClass)
Cartesian Product (X)
This is used to combine data from two different relations(tables) into one and fetch data from the combined
relation.
Syntax: A X B
For example, if we want to find the information for Regular Class and Extra Class which are conducted during
morning, then, we can use the following operation:
σtime = 'morning' (RegularClass X ExtraClass)
For the above query to work, both RegularClass and ExtraClass should have the attribute time.
Rename Operation (ρ)
This operation is used to rename the output relation for any query operation which returns result like Select,
Project etc. Or to simply rename a relation(table)
Syntax: ρ(RelationNew, RelationOld)
Apart from these common operations Relational Algebra is also used for Join operations like,
Natural Join
Outer Join
Theta join etc.
What are Keys in DBMS?
KEYS in DBMS is an attribute or set of attributes which helps you to identify a row(tuple) in a relation(table).
They allow you to find the relation between two tables. Keys help you uniquely identify a row in a table by a
combination of one or more columns in that table. Key is also helpful for finding unique record or row from the
table. Database key is also helpful for finding unique record or row from the table.

Learning Module on IM 201


129

In the above-given example, employee ID is a primary key because it uniquely identifies an employee record. In
this table, no other employee can have the same employee ID.
Why we need a Key?
Here are some reasons for using sql key in the DBMS system.
• Keys help you to identify any row of data in a table. In a real-world application, a table could contain
thousands of records. Moreover, the records could be duplicated. Keys ensure that you can uniquely identify
a table record despite these challenges.
• Allows you to establish a relationship between and identify the relation between tables
• Help you to enforce identity and integrity in the relationship.
Types of Keys in Database Management System
There are mainly seven different types of Keys in DBMS and each key has it’s different functionality:
• Super Key - A super key is a group of single or multiple keys which identifies rows in a table.
• Primary Key - is a column or group of columns in a table that uniquely identify every row in that table.
• Candidate Key - is a set of attributes that uniquely identify tuples in a table. Candidate Key is a super key
with no repeated attributes.
• Alternate Key - is a column or group of columns in a table that uniquely identify every row in that table.
• Foreign Key - is a column that creates a relationship between two tables. The purpose of Foreign keys is to
maintain data integrity and allow navigation between two different instances of an entity.
• Compound Key - has two or more attributes that allow you to uniquely recognize a specific record. It is
possible that each column may not be unique by itself within the database.
• Composite Key - An artificial key which aims to uniquely identify each record is called a surrogate key.
These kind of key are unique because they are created when you don't have any natural primary key.
• Surrogate Key - An artificial key which aims to uniquely identify each record is called a surrogate key.
These kind of key are unique because they are created when you don't have any natural primary key.
What is the Super key?
A superkey is a group of single or multiple keys which identifies rows in a table. A Super key may have additional
attributes that are not needed for unique identification.

Learning Module on IM 201


130

In the above-given example, EmpSSN, EmpSSN+Empname, EmpNum, EmpNum+Empname,


EmpNum+Empname+EmpSSN are superkeys.
What is a Primary Key?
PRIMARY KEY is a column or group of columns in a table that uniquely identify every row in that table. The
Primary Key can't be a duplicate meaning the same value can't appear more than once in the table. A table cannot
have more than one primary key.
Rules for defining Primary key:
• Two rows can't have the same primary key value
• It must for every row to have a primary key value.
• The primary key field cannot be null.
• The value in a primary key column can never be modified or updated if any foreign key refers to that primary
key.
Example:
In the following example, StudID is a Primary Key.

What is the Alternate key?


ALTERNATE KEYS is a column or group of columns in a table that uniquely identify every row in that table. A
table can have multiple choices for a primary key but only one can be set as the primary key. All the keys which
are not primary key are called an Alternate Key.

Learning Module on IM 201


131

Example:
In this table, StudID, Roll No, Email are qualified to become a primary key. But since StudID is the primary key,
Roll No, Email becomes the alternative key.

What is a Candidate Key?


CANDIDATE KEY is a set of attributes that uniquely identify tuples in a table. Candidate Key is a super key
with no repeated attributes. The Primary key should be selected from the candidate keys. Every table must have
at least a single candidate key. A table can have multiple candidate keys but only a single primary key.
Properties of Candidate key:
• It must contain unique values
• Candidate key may have multiple attributes
• Must not contain null values
• It should contain minimum fields to ensure uniqueness
• Uniquely identify each record in a table
Example: In the given table Stud ID, Roll No, and email are candidate keys which help us to uniquely identify
the student record in the table.

Learning Module on IM 201


132

What is the Foreign key?


FOREIGN KEY is a column that creates a relationship between two tables. The purpose of Foreign keys is to
maintain data integrity and allow navigation between two different instances of an entity. It acts as a cross-
reference between two tables as it references the primary key of another table.

In this key in dbms example, we have two table, teach and department in a school. However, there is no way to
see which search work in which department.
In this table, adding the foreign key in Deptcode to the Teacher name, we can create a relationship between the
two tables.

Learning Module on IM 201


133

This concept is also known as Referential Integrity.


What is the Compound key?
COMPOUND KEY has two or more attributes that allow you to uniquely recognize a specific record. It is possible
that each column may not be unique by itself within the database. However, when combined with the other column
or columns the combination of composite keys become unique. The purpose of the compound key in database is
to uniquely identify each record in the table.

In this example, OrderNo and ProductID can't be a primary key as it does not uniquely identify a record. However,
a compound key of Order ID and Product ID could be used as it uniquely identified each record.
What is the Composite key?
COMPOSITE KEY is a combination of two or more columns that uniquely identify rows in a table. The
combination of columns guarantees uniqueness, though individually uniqueness is not guaranteed. Hence, they
are combined to uniquely identify records in a table.
The difference between compound and the composite key is that any part of the compound key can be a foreign
key, but the composite key may or maybe not a part of the foreign key.
What is a Surrogate key?
SURROGATE KEYS is an artificial key which aims to uniquely identify each record is called a surrogate key.
This kind of partial key in dbms is unique because it is created when you don't have any natural primary key.
They do not lend any meaning to the data in the table. Surrogate key is usually an integer. A surrogate key is a
value generated right before the record is inserted into a table.

Learning Module on IM 201


134

Above, given example, shown shift timings of the different employee. In this example, a surrogate key is needed
to uniquely identify each employee.
Surrogate keys in sql are allowed when:
• No property has the parameter of the primary key.
• In the table when the primary key is too big or complicated.
Difference Between Primary key & Foreign key

Learning Module on IM 201


135

M2:L2 EXERCISE.
Identify the relational keys that is being asked on each problem, use the below tables to create your answer; write
your answer on the lines provided.

a. Superkeys in table students:


__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________
b. Superkeys in table subject:
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________
______________________________________________________________________________
c. Candidate keys in all tables:
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
______________________________

Application

Learning Module on IM 201


136

Create a relationship between the three (3) tables given below by providing correct foreign keys to the blank
columns; use the below facts to create your answer. Encircle all primary keys on each table.
• Below is the teaching load of the Professors:
ProfID SubjectCode
101 CS101
102 IS101
103 IT101

• All BSIT students are currently enrolled in IT101.


• All BSCS students are currently enrolled in CS101.
• All BSIS students are currently enrolled in IS101.

table: student
studentID studentName Address Course
2015123 Jenny Brgy. 1 BSIT
2015124 Albert Brgy. 2 BSIT
2015125 Simon Brgy. 1 BSCS
2015126 Jean Brgy. 1 BSCS
2015127 Veronica Brgy. 1 BSIT
2015128 Sean Brgy. 2 BSCS
2015129 Dave Brgy. 3 BSIS
2015130 Mae Brgy. 4 BSIS

table: subject
SubjectCode SubjectName
IT101 Intro to IT
CS101 Intro to CS
IS101 Intro to IS

table: prof
ProfID ProfName Department
101 John CS
102 Smith IS
103 Robert IT

Learning Module on IM 201


137

Summary of the Lesson:


1. In this chapter, we introduced the SQL database language.
2. A database most often contains one or more tables. Each table is identified by a name. Most of the actions
you need to perform on a database are done with SQL statements.
3. A key in SQL is an attribute or set of attributes which helps you to identify a row(tuple) in a relation(table).
DBMS keys allow you to establish a relationship between and identify the relation between tables.
Seven Types of DBMS keys are Super, Primary, Candidate, Alternate, Foreign, Compound, Composite, and
Surrogate Key.
• A super key is a group of single or multiple keys which identifies rows in a table.
• A column or group of columns in a table which helps us to uniquely identifies every row in that table is
called a primary key.
• All the keys which are not primary key are called an alternate key.
• A super key with no repeated attribute is called candidate key.
• A compound key is a key which has many fields which allow you to uniquely recognize a specific record.
• A key which has multiple attributes to uniquely identify rows in a table is called a composite key.
• An artificial key which aims to uniquely identify each record is called a surrogate key.
• Primary Key never accept null values while a foreign key may accept multiple null values.

Learning Module on IM 201


138

M2:L2 Enrichment Activity:


Answer the below problems using the three (3) tables on the previous exercise.
a. Primary keys in student and subject tables:
__________________________________________________________________________________________
__________________________________________________________________
b. Composite key in table enroll.
__________________________________________________________________________________________
__________________________________________________________________
c. Secondary keys in table student and subject.
__________________________________________________________________________________________
__________________________________________________________________
c. Foreign key in table student.
__________________________________________________________________________________________
________________________________________________________________________________

Learning Module on IM 201


139

M2 Assessment:
I. Multiple choice. Write your answer on the space provided before each number.

________1. A column which is added to create a relationship with another table.


a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________2. Helps to maintain data integrity and also allows navigation between two different instances of an
entity.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________3. A group of single or multiple keys which identifies rows in a table.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________4. A key that may have additional attributes that are not needed for unique identification.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________5. An attribute whose values match primary key values in the related table.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________6. An artificial key which aims to uniquely identify each record.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________7. A minimal super key.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________8. With SQL, how do you select all the records from a table named "Persons" where the "LastName" is
alphabetically between (and including) "Hansen" and "Pettersen"?
a. SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Persons
b. SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'
c. SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName<'Pettersen'
________9. Which SQL statement is used to extract data from a database?
d. EXTRACT e. GET f. OPEN g. SELECT
________10. Which SQL statement is used to update data in a database?
h. MODIFY i. UPDATE j. SAVE AS k. SAVE

Learning Module on IM 201


140

________11. Which SQL statement is used to delete data from a database?


l. COLLAPSE m. REMOVE n. DELETE
________12. Which SQL statement is used to insert new data in a database?
o. INSERT NEW s. ADD NEW q. INSERT INTO r. ADD RECORD
________13. With SQL, how do you select a column named "FirstName" from a table named "Persons"?
e. EXTRACT FirstName FROM Persons d. SELECT Persons.FirstName z. SELECT FirstName FROM
Persons
________14. With SQL, how do you select all the columns from a table named "Persons"?
a. SELECT [all] FROM Persons o. SELECT *.Persons y. SELECT Persons e. SELECT * FROM
Persons
________15. With SQL, how do you select all the records from a table named "Persons" where the value of the
column "FirstName" is "Peter"?
r. SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter'
p. SELECT * FROM Persons WHERE FirstName<>'Peter'
h. SELECT * FROM Persons WHERE FirstName='Peter'
s. SELECT [all] FROM Persons WHERE FirstName='Peter'
________16. With SQL, how do you select all the records from a table named "Persons" where the value of the
column "FirstName" starts with an "a"?
p. SELECT * FROM Persons WHERE FirstName='%a%'
o. SELECT * FROM Persons WHERE FirstName LIKE 'a%'
u. SELECT * FROM Persons WHERE FirstName='a'
y. SELECT * FROM Persons WHERE FirstName LIKE '%a'
________17. With SQL, how do you select all the records from a table named "Persons" where the "FirstName"
is "Peter" and the "LastName" is "Jackson"?
c. SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson'
v. SELECT FirstName='Peter', LastName='Jackson' FROM Persons
f. SELECT * FROM Persons WHERE FirstName<>'Peter' AND LastName<>'Jackson'
________18. Which SQL statement is used to return only different values?

Learning Module on IM 201


141

d. SELECT UNIQUE o. SELECT DIFFERENT g. SELECT DISTINCT


________19. With SQL, how can you insert a new record into the "Persons" table?
r. INSERT ('Jimmy', 'Jackson') INTO Persons
s. INSERT VALUES ('Jimmy', 'Jackson') INTO Persons
t. INSERT INTO Persons VALUES ('Jimmy', 'Jackson')
________20. With SQL, how can you insert "Olsen" as the "LastName" in the "Persons" table?
p. INSERT INTO Persons ('Olsen') INTO LastName
q. INSERT ('Olsen') INTO Persons (LastName)
e. INSERT INTO Persons (LastName) VALUES ('Olsen')
________21. How can you change "Hansen" into "Nilsen" in the "LastName" column in the Persons table?
v. UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'
b. MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'
f. UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'
p. MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen
________22. With SQL, how can you return the number of records in the "Persons" table?
o. SELECT COLUMNS(*) FROM Persons
w. SELECT NO(*) FROM Persons
p. SELECT COUNT(*) FROM Persons
q. SELECT LEN(*) FROM Persons

II. Write the SQL statement for the below problems; write your answer on the lines provided.
Table name: employee

Learning Module on IM 201


142

1. SQL statement to select all employees with an Fname starting with "j":
__________________________________________________________________________________________
__________________________________________________________________
2. SQL statement to select all employees with an Lname ending with "g":
__________________________________________________________________________________________
__________________________________________________________________
3. SQL statement to select all employees with an Address that have "as" in any position:
__________________________________________________________________________________________
__________________________________________________________________
4. SQL statement to select all employees with an Address that have "e" in the second position:
__________________________________________________________________________________________
__________________________________________________________________
d. SQL statement to select all employees with an Fname that starts with "b" and are at least 3 characters in length:
__________________________________________________________________________________________
__________________________________________________________________
e. SQL statement to select all employees with an Fname that starts with "b" and ends with "e":
__________________________________________________________________________________________
__________________________________________________________________
f. SQL statement to select all employees with an Address that does NOT start with "f":
__________________________________________________________________________________________
__________________________________________________________________
8. SQL statement to select all employees with an Fname starting with "e":
__________________________________________________________________________________________
__________________________________________________________________
9. SQL statement to select all employees with an Lname ending with "c":
__________________________________________________________________________________________
__________________________________________________________________
10. SQL statement to select all employees with an Address that have "if" in any position:
__________________________________________________________________________________________
__________________________________________________________________11. SQL statement to select all
employees with an Address that have "t" in the second position:

Learning Module on IM 201


143

__________________________________________________________________________________________
__________________________________________________________________
12. SQL statement to select all employees with an Fname that starts with "c" and are at least 3 characters in length:
__________________________________________________________________________________________
__________________________________________________________________
13. SQL statement to select all employees with an Fname that starts with "w" and ends with "e":
__________________________________________________________________________________________
__________________________________________________________________
14. SQL statement to select all employees with an Address that does NOT start with "k":
__________________________________________________________________________________________
__________________________________________________________________
15. SQL statement to display distinct values of SSN of all male employees.
__________________________________________________________________________________________
__________________________________________________________________
16. SQL statement to display distinct values of SSN of all female employees.
__________________________________________________________________________________________
__________________________________________________________________
17. SQL statement to display distinct values of SSN of all employees.
__________________________________________________________________________________________
__________________________________________________________________
18. SQL statement to display the total salary of all employees.
__________________________________________________________________________________________
__________________________________________________________________
19. SQL statement to count all employees.
__________________________________________________________________________________________
__________________________________________________________________
20. SQL statement to count all female and male employees.
__________________________________________________________________________________________
__________________________________________________________________

Learning Module on IM 201


144

I. Course Code IM 201


II. Course Title Fundamentals of Database Systems
III. Module Number 3
IV. Module Title Database Normalization and SQL Join and ER Model
V. Overview of the Module Database Normalization is a technique of organizing the data in the
database. Normalization is a systematic approach of decomposing tables to
eliminate data redundancy(repetition) and undesirable characteristics like
Insertion, Update and Deletion Anomalies. It is a multi-step process that
puts data into tabular form, removing duplicated data from the relation
tables.
This module will also discuss joins. A JOIN clause is used to combine rows
from two or more tables, based on a related column between them. It will
also tackle the ER modeling and how to create ER diagram.
VI. Module Outcomes What you will learn in this chapter: how normalization protects databases
from anomalies; rules on how to create 1NF, 2NF, 3NF and BCNF. You
will also be able to understand and create: inner join; left join; right join;
and full join; the main characteristics of entity relationship components;
how relationships between entities are defined and refined; how ERD
components affect database design and implementation.

Learning Module on IM 201


145

Lesson 1. Database Normalization and SQL Join


Database Normalization is a technique of organizing the data in the database. Normalization is a systematic
approach of decomposing tables to eliminate data redundancy(repetition) and undesirable characteristics like
Insertion, Update and Deletion Anomalies. It is a multi-step process that puts data into tabular form, removing
duplicated data from the relation tables.
This module will also discuss joins. A JOIN clause is used to combine rows from two or more tables, based on a
related column between them.
Lesson Objectives:
What you will learn in this chapter:

1. How normalization protects databases from anomalies.


2. Rules on how to create 1st normal form.
3. Rules on how to create 2nd normal form.
4. Rules on how to create 3rd normal form.
5. Rules on how to create BCNF.
You will also be able to understand and create:
6. inner join;
7. left join;
8. right join; and
9. full join.

Discussion:
Normalization is used for mainly two purposes,
• Eliminating redundant(useless) data.
• Ensuring data dependencies make sense i.e data is logically stored.

Problems Without Normalization


If a table is not properly normalized and have data redundancy then it will not only eat up extra memory space
but will also make it difficult to handle and update the database, without facing data loss. Insertion, Updation and

Learning Module on IM 201


146

Deletion Anomalies are very frequent if database is not normalized. To understand these anomalies let us take an
example of a Student table.

In the table above, we have data of 4 Computer Sci. students. As we can see, data for the fields branch, hod(Head
of Department) and office_tel is repeated for the students who are in the same branch in the college, this is Data
Redundancy.
Insertion Anomaly
Suppose for a new admission, until and unless a student opts for a branch, data of the student cannot be inserted,
or else we will have to set the branch information as NULL.
Also, if we have to insert data of 100 students of same branch, then the branch information will be repeated for
all those 100 students.
These scenarios are nothing but Insertion anomalies.
Updation Anomaly
What if Mr. X leaves the college? or is no longer the HOD of computer science department? In that case all the
student records will have to be updated, and if by mistake we miss any record, it will lead to data inconsistency.
This is Updation anomaly.
Deletion Anomaly
In our Student table, two different informations are kept together, Student information and Branch information.
Hence, at the end of the academic year, if student records are deleted, we will also lose the branch information.
This is Deletion anomaly.
Normalization Rule
Normalization rules are divided into the following normal forms:
First Normal Form
Second Normal Form

Learning Module on IM 201


147

Third Normal Form


BCNF
First Normal Form (1NF)
For a table to be in the First Normal Form, it should follow the following 4 rules:
1. It should only have single(atomic) valued attributes/columns.
2. Values stored in a column should be of the same domain
3. All the columns in a table should have unique names.
4. And the order in which data is stored, does not matter.

Second Normal Form (2NF)


For a table to be in the Second Normal Form,
1. It should be in the First Normal form.
2. And, it should not have Partial Dependency.

Third Normal Form (3NF)


A table is said to be in the Third Normal Form when,

1. It is in the Second Normal form.


2. And, it doesn't have Transitive Dependency.

Boyce and Codd Normal Form (BCNF)


Boyce and Codd Normal Form is a higher version of the Third Normal form. This form deals with certain type of
anomaly that is not handled by 3NF. A 3NF table which does not have multiple overlapping candidate keys is
said to be in BCNF. For a table to be in BCNF, following conditions must be satisfied:

1. It must be in 3rd Normal Form


2. and, for each functional dependency ( X → Y ), X should be a super Key.

What is First Normal Form (1NF)?


The 1st Normal form expects you to design your table in such a way that it can easily be extended and it is easier
for you to retrieve data from it whenever required.

Learning Module on IM 201


148

Rules for First Normal Form


The first normal form expects you to follow a few simple rules while designing your database, and they are:
Rule 1: Single Valued Attributes
Each column of your table should be single valued which means they should not contain multiple values. We will
explain this with help of an example later, let's see the other rules for now.
Rule 2: Attribute Domain should not change
This is more of a "Common Sense" rule. In each column the values stored must be of the same kind or type.
For example: If you have a column dob to save date of births of a set of people, then you cannot or you must not
save 'names' of some of them in that column along with 'date of birth' of others in that column. It should hold only
'date of birth' for all the records/rows.
Rule 3: Unique name for Attributes/Columns
This rule expects that each column in a table should have a unique name. This is to avoid confusion at the time
of retrieving data or performing any other operation on the stored data.
If one or more columns have same name, then the DBMS system will be left confused.
Rule 4: Order doesn't matters
This rule says that the order in which you store the data in your table doesn't matter.
Here is our table, with some sample data added to it.

Our table already satisfies 3 rules out of the 4 rules, as all our column names are unique, we have stored data in
the order we wanted to and we have not inter-mixed different type of data in columns.
But out of the 3 different students in our table, 2 have opted for more than 1 subject. And we have stored the
subject names in a single column. But as per the 1st Normal form each column must contain atomic value.
How to solve this Problem?
It's very simple, because all we have to do is break the values into atomic values.

Learning Module on IM 201


149

Here is our updated table and it now satisfies the First Normal Form.

By doing so, although a few values are getting repeated but values for the subject column are now atomic for each
record/row.
Using the First Normal Form, data redundancy increases, as there will be many columns with same data in
multiple rows but each row as a whole will be unique.
What is Second Normal Form?
For a table to be in the Second Normal Form, it must satisfy two conditions:
The table should be in the First Normal Form.
There should be no Partial Dependency.
What is Dependency?
Let's take an example of a Student table with columns student_id, name, reg_no(registration number), branch and
address(student's home address).

In this table, student_id is the primary key and will be unique for every row, hence we can use student_id to fetch
any row of data from this table.
Even for a case, where student names are same, if we know the student_id we can easily fetch the correct record.

Learning Module on IM 201


150

Hence we can say a Primary Key for a table is the column or a group of columns(composite key) which can
uniquely identify each record in the table.
I can ask from branch name of student with student_id 10, and I can get it. Similarly, if I ask for name of student
with student_id 10 or 11, I will get it. So all I need is student_id and every other column depends on it, or can be
fetched using it.
This is Dependency and we also call it Functional Dependency.
What is Partial Dependency?
Now that we know what dependency is, we are in a better state to understand what partial dependency is.
For a simple table like Student, a single column like student_id can uniquely identfy all the records in a table.
But this is not true all the time. So now let's extend our example to see if more than 1 column together can act as
a primary key.
Let's create another table for Subject, which will have subject_id and subject_name fields and subject_id will be
the primary key.

Now we have a Student table with student information and another table Subject for storing subject information.
Let's create another table Score, to store the marks obtained by students in the respective subjects. We will also
be saving name of the teacher who teaches that subject along with marks.

Learning Module on IM 201


151

In the score table we are saving the student_id to know which student's marks are these and subject_id to know
for which subject the marks are for.
Together, student_id + subject_id forms a Candidate Key for this table, which can be the Primary key.
Confused, how this combination can be a primary key?
See, if I ask you to get me marks of student with student_id 10, can you get it from this table? No, because you
don't know for which subject. And if I give you subject_id, you would not know for which student. Hence we
need student_id + subject_id to uniquely identify any row.
But where is Partial Dependency?
Now if you look at the Score table, we have a column names teacher which is only dependent on the subject, for
Java it's Java Teacher and for C++ it's C++ Teacher & so on.
Now as we just discussed that the primary key for this table is a composition of two columns which is student_id
& subject_id but the teacher's name only depends on subject, hence the subject_id, and has nothing to do with
student_id.
This is Partial Dependency, where an attribute in a table depends on only a part of the primary key and not on the
whole key.
How to remove Partial Dependency?
There can be many different solutions for this, but our objective is to remove teacher's name from Score table.
The simplest solution is to remove columns teacher from Score table and add it to the Subject table. Hence, the
Subject table will become:

Learning Module on IM 201


152

And our Score table is now in the second normal form, with no partial dependency.

Recap
For a table to be in the Second Normal form, it should be in the First Normal form and it should not have Partial
Dependency.
Partial Dependency exists, when for a composite primary key, any attribute in the table depends only on a part of
the primary key and not on the complete primary key.
To remove Partial dependency, we can divide the table, remove the attribute which is causing partial dependency,
and move it to some other table where it fits in well.

Third Normal Form (3NF)


Third Normal Form is an upgrade to Second Normal Form. When a table is in the Second Normal Form and has
no transitive dependency, then it is in the Third Normal Form.
So let's use the same example, where we have 3 tables, Student, Subject and Score.

Learning Module on IM 201


153

In the Score table, we need to store some more information, which is the exam name and total marks, so let's add
2 more columns to the Score table.

Requirements for Third Normal Form


For a table to be in the third normal form,
1. It should be in the Second Normal form.
2. And it should not have Transitive Dependency.

What is Transitive Dependency?

Learning Module on IM 201


154

With exam_name and total_marks added to our Score table, it saves more data now. Primary key for our Score
table is a composite key, which means it's made up of two attributes or columns → student_id + subject_id.
Our new column exam_name depends on both student and subject. For example, a mechanical engineering student
will have Workshop exam but a computer science student won't. And for some subjects you have Prctical exams
and for some you don't. So we can say that exam_name is dependent on both student_id and subject_id.
And what about our second new column total_marks? Does it depend on our Score table's primary key?
Well, the column total_marks depends on exam_name as with exam type the total score changes. For example,
practicals are of less marks while theory exams are of more marks.
But, exam_name is just another column in the score table. It is not a primary key or even a part of the primary
key, and total_marks depend on it.
This is Transitive Dependency. When a non-prime attribute depends on other non-prime attributes rather than
depending upon the prime attributes or primary key.
How to remove Transitive Dependency?
Again the solution is very simple. Take out the columns exam_name and total_marks from Score table and put
them in an Exam table and use the exam_id wherever required.

Advantage of removing Transitive Dependency


The advantage of removing transitive dependency are,
Amount of data duplication is reduced.
Data integrity achieved.

Learning Module on IM 201


155

Boyce-Codd Normal Form (BCNF)


Boyce-Codd Normal Form or BCNF is an extension to the third normal form, and is also known as 3.5 Normal
Form.
Rules for BCNF
For a table to satisfy the Boyce-Codd Normal Form, it should satisfy the following two conditions:
1. It should be in the Third Normal Form.
2. And, for any dependency A → B, A should be a super key.
The second point sounds a bit tricky, right? In simple words, it means, that for a dependency A → B, A cannot
be a non-prime attribute, if B is a prime attribute.
Example
Below we have a college enrolment table with columns student_id, subject and professor.

As you can see, we have also added some sample data to the table.
In the table above:
One student can enroll for multiple subjects. For example, student with student_id 101, has opted for subjects -
Java & C++
For each subject, a professor is assigned to the student.
And, there can be multiple professors teaching one subject like we have for Java.
What do you think should be the Primary Key?
Well, in the table above student_id, subject together form the primary key, because using student_id and subject,
we can find all the columns of the table.

Learning Module on IM 201


156

One more important point to note here is, one professor teaches only one subject, but one subject may have two
different professors.
Hence, there is a dependency between subject and professor here, where subject depends on the professor name.
This table satisfies the 1st Normal form because all the values are atomic, column names are unique and all the
values stored in a particular column are of same domain.
This table also satisfies the 2nd Normal Form as there is no Partial Dependency.
And, there is no Transitive Dependency, hence the table also satisfies the 3rd Normal Form.
But this table is not in Boyce-Codd Normal Form.
Why this table is not in BCNF?
In the table above, student_id, subject form primary key, which means subject column is a prime attribute.
But, there is one more dependency, professor → subject.
And while subject is a prime attribute, professor is a non-prime attribute, which is not allowed by BCNF.
How to satisfy BCNF?
To make this relation(table) satisfy BCNF, we will decompose this table into two tables, student table and
professor table.
Below we have the structure for both the tables.

Learning Module on IM 201


157

And now, this relation satisfy Boyce-Codd Normal Form.


A more Generic Explanation
In the picture below, we have tried to explain BCNF in terms of relations.

SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
Let's look at a selection from the "Orders" table:

Learning Module on IM 201


158

Then, look at a selection from the "Customers" table:

Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table.
The relationship between the two tables above is the "CustomerID" column.

Then, we can create the following SQL statement (that contains an INNER JOIN), that selects records that have
matching values in both tables:
Example

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate


FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

and it will produce something like this:

Learning Module on IM 201


159

Different Types of SQL JOINs


Here are the different types of the JOINs in SQL:
(INNER) JOIN: Returns records that have matching values in both tables.
LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table.
RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table.
FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table.

SQL INNER JOIN Keyword


The INNER JOIN keyword selects records that have matching values in both tables.
INNER JOIN Syntax

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;

Learning Module on IM 201


160

Demo Database
We will use the well-known Northwind sample database.
Below is a selection from the "Orders" table:

And a selection from the "Customers" table:

SQL INNER JOIN Example


The following SQL statement selects all orders with customer information:
Example

SELECT Orders.OrderID, Customers.CustomerName


FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;

OrderID CustomerName
10308 Ana Trujillo Emparedados
y helados

Learning Module on IM 201


161

10309 Hungry Owl All-Night


Grocers
10310 The Big Cheese

Note: The INNER JOIN keyword selects all rows from both tables as long as there is a match between the
columns. If there are records in the "Orders" table that do not have matches in "Customers", these orders will
not be shown!
JOIN Three Tables
The following SQL statement selects all orders with customer and shipper information:
Example

SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName


FROM ((Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID)
INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID);

Note: You can create Shippers table considering that it has ShipperID.

SQL LEFT JOIN Keyword


The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right
table (table2). The result is NULL from the right side, if there is no match.
LEFT JOIN Syntax

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;

Learning Module on IM 201


162

Note: In some databases LEFT JOIN is called LEFT OUTER JOIN.

Demo Database
We will use the well-known Northwind sample database.
Below is a selection from the "Customers" table:

And a selection from the "Orders" table:

SQL LEFT JOIN Example


The following SQL statement will select all customers, and any orders they might have:
Example

SELECT Customers.CustomerName, Orders.OrderID


FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;

Learning Module on IM 201


163

Note: The LEFT JOIN keyword returns all records from the left table (Customers), even if there are no matches
in the right table (Orders). Run the SQL statement to see the result; create the tables first before running the join
statement.

SQL RIGHT JOIN Keyword


The RIGHT JOIN keyword returns all records from the right table (table2), and the matched records from the left
table (table1). The result is NULL from the left side, when there is no match.
RIGHT JOIN Syntax

SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;

Note: In some databases RIGHT JOIN is called RIGHT OUTER JOIN.

Demo Database
We will use the well-known Northwind sample database.

Learning Module on IM 201


164

SQL RIGHT JOIN Example


The following SQL statement will return all employees, and any orders they might have placed:
Example

SELECT Orders.OrderID, Employees.LastName, Employees.FirstName


FROM Orders
RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;

Note: The RIGHT JOIN keyword returns all records from the right table (Employees), even if there are no matches
in the left table (Orders). Run the SQL statement to see the result; create the tables first before running the join
statement.

SQL FULL OUTER JOIN Keyword

Learning Module on IM 201


165

The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table
records.
Note: FULL OUTER JOIN can potentially return very large result-sets!
Tip: FULL OUTER JOIN and FULL JOIN are the same.
FULL OUTER JOIN Syntax

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;

Demo Database
We will use the well-known Northwind sample database.

Learning Module on IM 201


166

SQL FULL OUTER JOIN Example


The following SQL statement selects all customers, and all orders:

SELECT Customers.CustomerName, Orders.OrderID


FROM Customers
FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;

A selection from the result set may look like this:

Learning Module on IM 201


167

Note: The FULL OUTER JOIN keyword returns all matching records from both tables whether the other table
matches or not. So, if there are rows in "Customers" that do not have matches in "Orders", or if there are rows in
"Orders" that do not have matches in "Customers", those rows will be listed as well.

Learning Module on IM 201


168

M3:L1 EXERCISE.
a. If a table includes a ZIP code with every address, what 3NF rule does the table break? Why?
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
______________________________
b. What data anomalies can result from including postal codes in address data? How bad are they? How can you
mitigate the problems?
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________

c. Suppose you’re writing an application to record times for dragon boat races and consider the table below.
Assume the table’s key is Heat. What 1NF, 2NF, and 3NF rules does this design violate?

__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________

Learning Module on IM 201


169

__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
____________________________________
M3:L1 Application
Create the 1st, 2nd, and 3rd normal form of the given table below. Write your answer on the space provide.

a. 1NF

b. 2NF

Learning Module on IM 201


170

c. 3NF

Learning Module on IM 201


171

Summary of the Lesson:


1. Normalization protects a database from data anomalies.
2. 1NF rules:
1. Each column must have a unique name.
• The order of the rows and columns doesn’t matter.
• Each column must have a single data type.
• No two rows can contain identical values.
• Each column must contain a single value.
• Columns cannot contain repeating groups.
3. 2NF rules:
• It is in 1NF.
• All non-key fields depend on all key fields.
4. 3NF rules:
• It is in 2NF.
• It contains no transitive dependencies. (No non-key fields depend on other non-key fields.)
5. SQL JOIN inner, left, right and outer are used to combine tables.

Learning Module on IM 201


172

M3:L1 Enrichment Activity


Create the SQL command for the below problems; use the tables below for the instance of the database.

a. SQL command to inner join table DRUG and table PRESCRIPTION.


__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________
b. SQL command to display columns “drug_name” and “pres_dosage”.
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________
c. SQL command to display all columns of tables DOCTOR, PATIENT and PRESCRIPTION.
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________
d. SQL command to display all patient names and their assigned doctors.

Learning Module on IM 201


173

__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________
e. SQL command to join tables DRUG, PATIENT and PRESCRIPTION.
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________

Learning Module on IM 201


174

Lesson 2. Entity-Relationship Model


We present the modeling concepts of the entity–relationship (ER) model, which is a popular high-level conceptual
data model. This model and its variations are frequently used for the conceptual design of database applications,
and many database design tools employ its concepts. We describe the basic data-structuring concepts and
constraints of the ER model and discuss their use in the design of conceptual schemas for database applications.
We also present the diagrammatic notation associated with the ER model, known as ER diagrams.
Lesson Objectives:
In this lesson, you will learn:
1. The main characteristics of entity relationship components.
2. How relationships between entities are defined and refined.
3. How ERD components affect database design and implementation.
Discussion:
What is the ER Model?
ENTITY RELATIONAL (ER) MODEL is a high-level conceptual data model diagram. ER modeling helps you
to analyze data requirements systematically to produce a well-designed database. The Entity-Relation model
represents real-world entities and the relationship between them. It is considered a best practice to complete ER
modeling before implementing your database.
ER modeling helps you to analyze data requirements systematically to produce a well-designed database. So, it
is considered a best practice to complete ER modeling before implementing your database.
What is ER Diagrams?
ENTITY-RELATIONSHIP DIAGRAM (ERD) displays the relationships of entity set stored in a database. In
other words, we can say that ER diagrams help you to explain the logical structure of databases. At first look, an
ER diagram looks very similar to the flowchart. However, ER Diagram includes many specialized symbols, and
its meanings make this model unique. The purpose of ER Diagram is to represent the entity framework
infrastructure.
Facts about ER Diagram Model:
• ER model allows you to draw Database Design
• It is an easy to use graphical tool for modeling data
• Widely used in Database Design
• It is a GUI representation of the logical structure of a Database
• It helps you to identifies the entities which exist in a system and the relationships between those entities
Why use ER Diagrams?
Here, are prime reasons for using the ER Diagram

Learning Module on IM 201


175

• Helps you to define terms related to entity relationship modeling


• Provide a preview of how all your tables should connect, what fields are going to be on each table
• Helps to describe entities, attributes, relationships
• ER diagrams are translatable into relational tables which allows you to build databases quickly
• ER diagrams can be used by database designers as a blueprint for implementing data in specific software
applications
• The database designer gains a better understanding of the information to be contained in the database with the
help of ERP diagram
• ERD is allowed you to communicate with the logical structure of the database to users
Components of the ER Diagram
This model is based on three basic concepts:
1. Entities
2. Attributes
3. Relationships

Example
For example, in a University database, we might have entities for Students, Courses, and Lecturers. Students
entity can have attributes like Rollno, Name, and DeptID. They might have relationships with Courses and
Lecturers.

Learning Module on IM 201


176

WHAT IS ENTITY?
A real-world thing either living or non-living that is easily recognizable and no recognizable. It is anything in the
enterprise that is to be represented in our database. It may be a physical thing or simply a fact about the enterprise
or an event that happens in the real world.
An entity can be place, person, object, event or a concept, which stores data in the database. The characteristics
of entities are must have an attribute, and a unique key. Every entity is made up of some 'attributes' which represent
that entity.
Examples of entities:
Person: Employee, Student, Patient
Place: Store, Building
Object: Machine, product, and Car
Event: Sale, Registration, Renewal
Concept: Account, Course

Learning Module on IM 201


177

Relationship
Relationship is nothing but an association among two or more entities. E.g., Tom works in the Chemistry
department.

Learning Module on IM 201


178

Relationships are associations between entities (sometimes they are referred to as data associations). Figure above
is an entity-relationship (E-R) diagram that shows various types of relationships.
The first type of relationship is a one-to-one relationship (designated as 1:1). The diagram shows that there is
only one PRODUCT PACKAGE for each PRODUCT. The second one-to-one relationship shows that each
EMPLOYEE has a unique OFFICE. Notice that all these entities can be described further (a product price would
not be an entity, nor would a phone extension).
Another type of relationship is a one-to-many (1:M) or a many-to-one association. As shown in the figure, a
PHYSICIAN in a health maintenance organization is assigned many PATIENTS, but a PATIENT is assigned
only one PHYSICIAN. Another example shows that an EMPLOYEE is a member of only one DEPARTMENT,
but each DEPARTMENT has many EMPLOYEES.
Finally, a many-to-many relationship (designated as M:N) describes the possibility that entities may have many
associations in either direction. For example, a STUDENT can have many COURSE(s), and at the same time a
COURSE may have many STUDENT(s) enrolled in it. The second example shows that a SALESPERSON can
call on many CITY(s) and a CITY can be a sales area for many SALESPERSON(s).
The standard symbols for crow’s foot notation, the official explanation of the symbols, and what they actually
mean, are all given in Figure 13.3. Notice that the symbol for an entity is a rectangle.

Learning Module on IM 201


179

An entity is defined as a class of a person, place, or thing. A rectangle with a diamond inside stands for an
associative entity, which is used to join two entities. A rectangle with an oval in it stands for an attributive entity,
which is used for repeating groups.
When a straight line connects two plain entities and the ends of the line are both marked with two short marks
(||), a one-to-one relationship exists. Following that you will notice a crow’s foot with a short mark (|); when this
notation links entities, it indicates a relationship of one-to-one or one-to-many (to one or more).
Entities linked with a straight line plus a short mark (|) and a zero (which looks more like a circle, O) are depicting
a relationship of one-to-zero or one-to-one (only zero or one). A fourth type of link for relating entities is drawn
with a straight line marked on the end with a zero (O) followed by a crow’s foot. This type shows a zero-to-zero,
zero-to-one, or zero-to-many relationships.
Finally, a straight line linking entities with a crow’s foot at the end depicts a relationship to more than one.
Entities take part in relationships. We can often identify relationships with verbs or verb phrases.
For example:
• You are attending this lecture
• I am giving the lecture
• Just loke entities, we can classify relationships according to relationship-types:
• A student attends a lecture
• A lecturer is giving a lecture.

Attributes
It is a single-valued property of either an entity-type or a relationship-type. For example, a lecture might have
attributes: time, date, duration, place, etc.
Steps to Create an ERD
Following are the steps to create an ERD.
Let's study them with an example:
In a university, a Student enrolls in Courses. A student must be assigned to at least one or more Courses. Each
course is taught by a single Professor. To maintain instruction quality, a Professor can deliver only one course.
Step 1) Entity Identification
We have three entities
Student
Course

Learning Module on IM 201


180

Professor

Step 2) Relationship Identification


We have the following two relationships
The student is assigned a course
Professor delivers a course

Step 3) Cardinality Identification


For them problem statement we know that,
A student can be assigned multiple courses
A Professor can deliver only one course

Step 4) Identify Attributes


You need to study the files, forms, reports, data currently maintained by the organization to identify attributes.
You can also conduct interviews with various stakeholders to identify entities. Initially, it's important to identify
the attributes without mapping them to a particular entity.
Once, you have a list of Attributes, you need to map them to the identified entities. Ensure an attribute is to be
paired with exactly one entity. If you think an attribute should belong to more than one entity, use a modifier to
make it unique.
Once the mapping is done, identify the primary Keys. If a unique key is not readily available, create one.

Learning Module on IM 201


181

Step 5) Create the ERD


A more modern representation of ERD Diagram

NOTE: Exercise, application and activity do not have attributes.

Learning Module on IM 201


182

M3:L2 EXERCISE.
Create the ER Diagram for each problem; use the space provided to draw your answer.
a. One EMPLOYEE is assigned to one PHONE EXTENSION.

b. Many EMPLOYEES are members of a DEPARTMENT.

c. An EMPLOYEE is assigned to an OFFICE.

d. One CARGO AIRCRAFT will serve one or more DISTRIBUTION CENTERs.

e. SYSTEMS ANALYST may be assigned to MANY PROJECTS.

M3:L2 Application
a. The physician treats the illness a PATIENT has. Many PATIENT(s) experience many TREATMENT(s).
TREATMENT(s) can include the taking of PRESCRIPTION(s). Create the ERD of the above facts. Draw your
answer on the space provided.
Tip: You should be creating a single ERD with interconnected entities.

Learning Module on IM 201


183

b. The PATRON actually makes a one or more RESERVATION. RESERVATION(s) is/are for a
CONCERT/SHOW. Create the ERD of the above facts. Draw your answer on the space provided.

Learning Module on IM 201


184

Summary of the Lesson:


1. In this chapter we presented the modeling concepts of a high-level conceptual data model, the entity–
relationship (ER) model.
2. Then we discussed the ER model concepts at the schema or “intension” level:
• Entity types and their corresponding entity sets
• Key attributes of entity types
• Value sets (domains) of attributes
3.We presented two methods for specifying the structural constraints on relationship type which are the
Cardinality ratios (1:1, 1:N, M:N)

Learning Module on IM 201


185

M3:L2 Enrichment Activity


Create the ER Diagram for each problem; use the space provided to draw your answer.
a. A MACHINE may or may not be undergoing SCHEDULED MAINTENANCE.

b. “One or many SALESPERSONs are assigned to one or more CUSTOMERs.

c. One or more EMPLOYEEs may or may not be assigned to the HOME OFFICE.

d. Many PASSENGERs are flying to many DESTINATIONs.

Learning Module on IM 201


186

M3 Assessment:
I. Define the connection of the below paired entities whether it is 1:1, 1:M or M:N based on the given
scenario. Write your answer in column connectivity.
ABC College is divided into several schools. Each school is composed of several departments. Each department
may offer courses. Each department may have many professors assigned to it. Each professor may teach up to
four classes; each class is section of course. Student may enroll in several classes.
Each department has several students. Each student has only a single major and is associated with a single
department. Each student has an advisor in his or her department. Each advisor counsels several students. The
relationship between class is taught in a room and the room in the building. Professor can only teach in one school.
Item
No. Entity Connectivity Entity
1. School Department
2. Department Student
3. Department Professor
4. Department Course
5. Course Class
6. Professor School
7. Professor Department
8. Professor Class
9. Professor Student
10. Student Class
11. Building Room
12. Room Class

I. Create the 1st, 2nd and 3rd normal form of the below table. Use the space provided below for your
answer.

1. 1NF

Learning Module on IM 201


187

2. 2NF

3. 3NF

Learning Module on IM 201


188

II. Create the INNER, LEFT and RIGHT JOIN of the below tables.

Table name: Customerx

Table name: Ordery

1. INNER JOIN
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
______________________________________________________________________

Learning Module on IM 201


189

2. LEFT JOIN
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
______________________________________________________________________
3. RIGHT JOIN
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
______________________________________________________________________

Learning Module on IM 201


190

References/Attributions:
Kenneth E. Kendall & Julie E. Kendall, 2018, "System Analysis and Design, 10th Edition"

Rod Stephens, 2015, "Beginning Software Engineering"

Ramez Elmasri, Shamkant B. Navathe, 2015, “Fundamentals of Database Systems”

https://www.studytonight.com/dbms
https://www.guru99.com/
https://www.w3schools.com/sql
https://www.tutorialspoint.com/

Learning Module on IM 201

You might also like