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

SQL

UML (Unified Modeling Language) is a standardized visual modeling language for specifying, visualizing, and documenting software systems, developed by the Object Management Group (OMG) in 1997. It encompasses various diagrams to represent both static and dynamic aspects of systems, including use case diagrams that capture system requirements and actor interactions. UML supports object-oriented analysis and design, utilizing concepts such as classes, objects, inheritance, and polymorphism to model real-world entities and their relationships.

Uploaded by

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

SQL

UML (Unified Modeling Language) is a standardized visual modeling language for specifying, visualizing, and documenting software systems, developed by the Object Management Group (OMG) in 1997. It encompasses various diagrams to represent both static and dynamic aspects of systems, including use case diagrams that capture system requirements and actor interactions. UML supports object-oriented analysis and design, utilizing concepts such as classes, objects, inheritance, and polymorphism to model real-world entities and their relationships.

Uploaded by

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

1|M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

UML (Unified Modeling Language)

UML is a standard language for specifying, visualizing, constructing, and documenting the of software
systems. UML was created by the Object Management Group (OMG). UML 1.0 specification draft was
proposed to the OMG in January 1997.

● UML has become an OMG standard


● UML is different from the other common programming languages such as C++, Java, COBOL, etc.
● UML is a pictorial language used to make software blueprints.
● UML can be described as a general-purpose visual modeling language to visualize, specify, construct, and
document software system.
● UML diagrams are not only made for developers but also for business users, common people, and anybody
interested to understand the system. The system can be a software or non-software system
● UML is not a programming language but tools can be used to generate code in various languages using
UML diagrams.
● UML has a direct relation with object-oriented analysis and design.
● The goals for developing UML is to define some general-purpose modeling language, which all modelers
can use and it also needs to be made simple to understand and use.

A CONCEPTUAL MODEL OF UML

A conceptual model can be defined as a model which is made of concepts and their relationships. A
conceptual model is the first step before drawing a UML diagram. It helps to understand the entities
in the real world and how they interact with each other.
The conceptual model of UML can be mastered by learning the following three major elements.

● UML building blocks


● Rules to connect the building blocks
● Common mechanisms of UML

OBJECT-ORIENTED CONCEPTS

UML is an analysis and design of object-oriented (OO).


An object contains both data and methods that control the data. The data represents the state of the
object. A class describes an object and they also form a hierarchy to model the real-world system. The
hierarchy is represented as inheritance. The classes can also be associated in different ways as per the
requirement.
Objects are the real-world entities that exist around us and the basic concepts such as abstraction,
encapsulation, inheritance, and polymorphism all can be represented using UML.
UML is powerful enough to represent all the concepts that exist in object-oriented analysis and design.
UML diagrams are representation of object-oriented concepts only.
Fundamental concepts of the object-oriented world:
● Objects − Objects represent an entity and the basic building block.
● Class − Class is the blue print of an object.
● Abstraction − Abstraction represents the behavior of a real-world entity.
● Encapsulation − Encapsulation is the mechanism of binding the data together, hiding them from outside world.
● Inheritance − Inheritance is the mechanism of making new classes from existing ones.
● Polymorphism − Is the mechanism to exists in different forms. The ability of different objects to respond in a
unique way to the same message.

OO ANALYSIS AND DESIGN


Analysis means the investigation of objects; Design means the collaboration of identified objects.
2|M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

The purpose of OO analysis is to identify objects of a system to be designed. This analysis is also done
for an existing system. After identifying the objects, their relationships are identified and finally the
design is produced.

Purpose of OO analysis and design:


● Identifying the objects of a system.
● Identifying their relationships.
● Making a design, executable using OO languages.

Steps where the OO concepts are applied and implemented.


OO Analysis → OO Design → OO Implementation

The above three points can be described in detail as −


● OO Analysis - The objects should be identified with responsibilities. Responsibilities are the functions
performed by the object. Each and every object has some type of responsibilities to be performed.
● OO Design - The objects are collaborated according to their intended association.
● OO Implementation - The design is implemented using OO languages such as Java, C++, etc.

Role of UML in OO Design


● Things
● Relationships
● Diagrams

THINGS
Things are the most important building blocks of UML. Things can be −
● Structural
● Behavioral
● Grouping
● Annotational

STRUCTURAL THINGS

Define the static part of the model. They represent the physical and conceptual elements. Following
are the brief descriptions of the structural things.

Class − Class represents a set of objects having similar responsibilities.

Interface − Interface defines a set of operations, which specify the responsibility of a class.

Collaboration −Collaboration defines an interaction between elements.

Use case −Use case represents a set of actions performed by a system for a specific goal.

Component −Component describes the physical part of a system.


3|M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Node − A node can be defined as a physical element that exists at run time.

BEHAVIORAL THINGS

A behavioral thing consists of the dynamic parts of UML model. Following are the behavioral things −
Interaction − behavior that consist of a group of messages exchanged among elements to
accomplish a specific task.

State Machine − The sequence of states an object goes through in response to events. Events
are external factors responsible for state change

GROUPING THINGS

A mechanism to group UML elements together. There is only one grouping thing available −
Package − Package is the only one grouping thing available for gathering structural and
behavioral things.

ANNOTATIONAL THINGS

A mechanism to capture remarks, descriptions, and comments of UML model elements.


Note - It is the only one Annotational thing available. A note is used to render comments,
constraints, etc. of an UML element.

RELATIONSHIP

It shows how the elements are associated with each other and this association describes the
functionality of an application.
There are four kinds of relationships available.

DEPENDENCY

A relationship between two things in which change in one element also affects the other.
4|M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

ASSOCIATION

Association is basically a set of links that connects the elements of a UML model. It also describes how
many objects are taking part in that relationship.

GENERALIZATION

A relationship which connects a specialized element with a generalized element. It basically describes
the inheritance relationship in the world of objects.

REALIZATION

A relationship in which two elements are connected. One element describes some responsibility, which
is not implemented and the other one implements them. This relationship exists in case of interfaces.

UML DIAGRAMS

UML diagrams are the ultimate output of the entire discussion. All the elements, relationships are used to make
a complete UML diagram and the diagram represents a system. The visual effect of the UML diagram is the most
important part of the entire process. All the other elements are used to make it complete.

UML includes the following nine diagrams,

● Class diagram
● Object diagram
● Use case diagram
● Sequence diagram
● Collaboration diagram
● Activity diagram
● State chart diagram
● Deployment diagram
● Component diagram
5|M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Use Case diagrams


To model a system, the most important aspect is to capture the dynamic behavior. Dynamic behavior means the
behavior of the system when it is running/operating.

Only static behavior is not sufficient to model a system rather dynamic behavior is more important than static
behavior. In UML, there are five diagrams available to model the dynamic nature and use case diagram is one of
them. Now as we have to discuss that the use case diagram is dynamic in nature, there should be some internal
or external factors for making the interaction.

These internal and external agents are known as actors. Use case diagrams consists of actors, use cases and their
relationships. The diagram is used to model the system/subsystem of an application. A single use case diagram
captures a particular functionality of a system.

Hence to model the entire system, a number of use case diagrams are used.

PURPOSE OF USE CASE DIAGRAMS

The purpose of use case diagram is to capture the dynamic aspect of a system. However, this definition is too
generic to describe the purpose, as other four diagrams (activity, sequence, collaboration, and State-chart) also
have the same purpose. We will look into some specific purpose, which will distinguish it from other four
diagrams.

Use case diagrams are used to gather the requirements of a system including internal and external influences.
These requirements are mostly design requirements. Hence, when a system is analyzed to gather its
functionalities, use cases are prepared and actors are identified.

When the initial task is complete, use case diagrams are modelled to present the outside view.

In brief, the purposes of use case diagrams can be said to be as follows −

● Used to gather the requirements of a system.


● Used to get an outside view of a system.
● Identify the external and internal factors influencing the system.
● Show the interaction among the requirements are actors.

HOW TO DRAW A USE CASE DIAGRAM?

Use case diagrams are considered for high level requirement analysis of a system. When the requirements of a
system are analyzed, the functionalities are captured in use cases.

We can say that use cases are nothing but the system functionalities written in an organized manner. The second
thing which is relevant to use cases are the actors. Actors can be defined as something that interacts with the
system.

Actors can be a human user, some internal applications, or may be some external applications. When we are
planning to draw a use case diagram, we should have the following items identified.

1. Functionalities to be represented as use case


2. Actors
3. Relationships among the use cases and actors.

Use case diagrams are drawn to capture the functional requirements of a system. After identifying the above
items, we have to use the following guidelines to draw an efficient use case diagram

 The name of a use case is very important. The name should be chosen in such a way so that it can identify
the functionalities performed.
 Give a suitable name for actors.
 Show relationships and dependencies clearly in the diagram.
 Do not try to include all types of relationships, as the main purpose of the diagram is to identify the
requirements.
 Use notes whenever required to clarify some important points.
6|M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Following is a sample use case diagram representing the order management system. Hence, if we look into the
diagram then we will find three use cases (Order, SpecialOrder, and NormalOrder) and one actor which is the
customer.

The SpecialOrder and NormalOrder use cases are extended from Order use case. Hence, they have extended
relationship. Another important point is to identify the system boundary, which is shown in the picture. The actor
Customer lies outside the system as it is an external user of the system.

WHERE TO USE A USE CASE DIAGRAM?

As we have already discussed there are five diagrams in UML to model the dynamic view of a system. Now each
and every model has some specific purpose to use. Actually, these specific purposes are different angles of a
running system.

To understand the dynamics of a system, we need to use different types of diagrams. Use case diagram is one of
them and its specific purpose is to gather system requirements and actors.

Use case diagrams specify the events of a system and their flows. But use case diagram never describes how they
are implemented. Use case diagram can be imagined as a black box where only the input, output, and the
function of the black box is known.

These diagrams are used at a very high level of design. This high-level design is refined again and again to get a
complete and practical picture of the system. A well-structured use case also describes the pre-condition, post
condition, and exceptions. These extra elements are used to make test cases when performing the testing.

Although use case is not a good candidate for forward and reverse engineering, still they are used in a slightly
different way to make forward and reverse engineering. The same is true for reverse engineering. Use case
diagram is used differently to make it suitable for reverse engineering.

In forward engineering, use case diagrams are used to make test cases and in reverse engineering use cases are
used to prepare the requirement details from the existing application.

Use case diagrams can be used for −

 Requirement analysis and high-level design.


 Model the context of a system.
 Reverse engineering.
 Forward engineering.

USE CASE DIAGRAM NOTATIONS GUIDE


7|M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Use case diagram is a kind of UML diagram. Here is a list of Unified Modeling Language (UML) notations
supported in a UML use case diagram:

Icon Name
Use Case
Association
Actor
System
Include
Extend
Dependency
Generalization
Realization
Collaboration

USE CASE

A use case is the specification of a set of actions performed by a system, which yields an observable result that
is typically of value for one or more actors or other stakeholders of the system.

OMG UML SPECIFICATION

What is a use case in UML? According to the OMG Unified Modeling Language (OMG UML) specification (UML
Superstructure Specification version 2.4.1, page 606), use case is:

ASSOCIATION
8|M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Actor and use case can be associated to indicate that the actor participates in that use case. Therefore, an
association correspond to a sequence of actions between the actor and use case in achieving the use case.

OMG UML SPECIFICATION

What is an association in UML? According to the OMG Unified Modeling Language (OMG UML) specification
(UML Superstructure Specification version 2.4.1, page 36), association is:

An association describes a set of tuples whose values refer to typed instances. An instance of an association is
called a link. A link is a tuple with one value for each end of the association, where each value is an instance of
the type of the end.

An association specifies a semantic relationship that can occur between typed instances. It has at least two ends
represented by properties, each of which is connected to the type of the end. More than one end of the
association may have the same type.

An end property of an association that is owned by an end class or that is a navigable owned end of the
association indicates that the association is navigable from the opposite ends; otherwise, the association is not
navigable from the opposite ends.

ACTOR

Actors are the entities that interact with a system. Although in most cases, actors are used to represent the users
of system, actors can actually be anything that needs to exchange information with the system. So, an actor may
be people, computer hardware, other systems, etc.

Note that actor represents a role that a user can play but not a specific user. So, in a hospital information system,
you may have doctor and patient as actors but not Dr. John, Mrs. Brown as actors.

OMG UML SPECIFICATION

What is an actor in UML? According to the OMG Unified Modeling Language (OMG UML) specification (UML
Superstructure Specification version 2.4.1), actor is:

An actor specifies a role played by a user or any other system that interacts with the subject. (The term "role" is
used informally here and does not necessarily imply the technical definition of that term found elsewhere in this
specification.)

An Actor models a type of role played by an entity that interacts with the subject (e.g., by exchanging signals
and data) but which is external to the subject (i.e., in the sense that an instance of an actor is not a part of the
instance of its corresponding subject). Actors may represent roles played by human users, external hardware, or
other subjects. Note that an actor does not necessarily represent a specific physical entity but merely a particular
facet (i.e., “role") of some entity that is relevant to the specification of its associated use cases. Thus, a single
physical instance may play the role of several different actors and conversely, a given actor may be played by
multiple different instances.

SYSTEM
9|M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

The scope of a system can be represented by a system (shape), or sometimes known as a system boundary. The
use cases of the system are placed inside the system shape, while the actor who interact with the system are put
outside the system. The use cases in the system make up the total requirements of the system.

OMG UML SPECIFICATION

What is a system in UML? According to the OMG Unified Modeling Language (OMG UML) specification (UML
Superstructure Specification version 2.4.1, page 608), system is:

If a subject (or system boundary) is displayed, the use case ellipse is visually located inside the system boundary
rectangle. Note that this does not necessarily mean that the subject classifier owns the contained use cases, but
merely that the use case applies to that classifier.

INCLUDE

An include relationship specifies how the behavior for the inclusion use case is inserted into the behavior defined
for the base use case.

OMG UML SPECIFICATION

What is an include in UML? According to the OMG Unified Modeling Language (OMG UML) specification (UML
Superstructure Specification version 2.4.1, page 604), include is:

An include relationship defines that a use case contains the behavior defined in another use case.

EXTEND

An extend relationship specifies how the behavior of the extension use case can be inserted into the behavior
defined for the base use case.

OMG UML SPECIFICATION

What is an extend in UML? According to the OMG Unified Modeling Language (OMG UML) specification (UML
Superstructure Specification version 2.4.1, page 601), extend is:

A relationship from an extending use case to an extended use case that specifies how and when the behavior
defined in the extending use case can be inserted into the behavior defined in the extended use case.

...
10 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

This relationship specifies that the behavior of a use case may be extended by the behavior of another (usually
supplementary) use case. The extension takes place at one or more specific extension points defined in the
extended use case. Note, however, that the extended use case is defined independently of the extending use
case and is meaningful independently of the extending use case. On the other hand, the extending use case
typically defines behavior that may not necessarily be meaningful by itself. Instead, the extending use case defines
a set of modular behavior increments that augment an execution of the extended use case under specific
conditions.

Note that the same extending use case can extend more than one use case. Furthermore, an extending use case
may itself be extended.

DEPENDENCY

A dependency relationship represents that a model element relies on another model element for specification
and/or implementation.

OMG UML SPECIFICATION

What is a dependency in UML? According to the OMG Unified Modeling Language (OMG UML) specification
(UML Superstructure Specification version 2.4.1, page 61), dependency is:

A dependency is a relationship that signifies that a single or a set of model elements requires other model
elements for their specification or implementation. This means that the complete semantics of the depending
elements is either semantically or structurally dependent on the definition of the supplier element(s).

GENERALIZATION

A generalization relationship is used to represent inheritance relationship between model elements of same type.
The more specific model element share the same specification with. the more general the model element but
carries more details in extra.

OMG UML SPECIFICATION

What is a generalization in UML? According to the OMG Unified Modeling Language (OMG UML) specification
(UML Superstructure Specification version 2.4.1, page 70), generalization is:

A generalization is a taxonomic relationship between a more general classifier and a more specific classifier. Each
instance of the specific classifier is also an indirect instance of the general classifier. Thus, the specific classifier
inherits the features of the more general classifier.

REALIZATION

A realization is a relationship between a specification and its implementation.

OMG UML SPECIFICATION


11 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

What is a realization in UML? According to the OMG Unified Modeling Language (OMG UML) specification (UML
Superstructure Specification version 2.4.1, page 131), realization is:

Realization is a specialized abstraction relationship between two sets of model elements, one representing a
specification (the supplier) and the other represents an implementation of the latter (the client). Realization can
be used to model stepwise refinement, optimizations, transformations, templates, model synthesis, framework
composition, etc.

COLLABORATION

OMG UML SPECIFICATION

What is a collaboration in UML? According to the OMG Unified Modeling Language (OMG UML) specification
(UML Superstructure Specification version 2.4.1, page 174), collaboration is:

A collaboration describes a structure of collaborating elements (roles), each performing a specialized function,
which collectively accomplish some desired functionality. Its primary purpose is to explain how a system works
and, therefore, it typically only incorporates those aspects of reality that are deemed relevant to the explanation.
Thus, details, such as the identity or precise class of the actual participating instances are suppressed.
12 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

ER DIAGRAM

WHAT IS THE ER MODEL?

The ER or (Entity Relational Model) is a high-level conceptual data model diagram. Entity-Relation model is based
on the notion of real-world entities and the relationship between them. 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.

An Entity–relationship model (ER model) describes the structure of a database with the help of a diagram, which
is known as Entity Relationship Diagram (ER Diagram). An ER model is a design or blueprint of a database that
can later be implemented as a database. The main components of E-R model are: entity set and relationship set.

An ER diagram shows the relationship among entity sets. An entity set is a group of similar entities and these
entities can have attributes. In terms of DBMS, an entity is a table or attribute of a table in database, so by
showing relationship among tables and their attributes, ER diagram shows the complete logical structure of a
database.

Here are the geometric shapes and their meaning in an E-R Diagram

o Rectangle: Represents Entity sets.


o Ellipses: Attributes
o Diamonds: Relationship Set
o Lines: They link attributes to Entity Sets and Entity sets to Relationship Set
o Double Ellipses: Multivalued Attributes
o Dashed Ellipses: Derived Attributes
o Double Rectangles: Weak Entity Sets
o Double Lines: Total participation of an entity in a relationship set

As shown in the above diagram, an ER diagram has three main components:

1. Entity
2. Attribute
3. Relationship

1. ENTITY

An entity is an object or component of data. An entity is represented as rectangle in an ER diagram.


For example: In the following ER diagram we have two entities Student and College and these two entities have
many to one relationship as many student’s study in a single college. We will read more about relationships later,
for now focus on entities.
13 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Weak Entity:

An entity that cannot be uniquely identified by its own attributes and relies on the relationship with other entity
is called weak entity. The weak entity is represented by a double rectangle. For example – a bank account cannot
be uniquely identified without knowing the bank to which the account belongs, so bank account is a weak entity.

2. ATTRIBUTE

An attribute describes the property of an entity. An attribute is represented as Oval in an ER diagram. There are
four types of attributes:

1. Key attribute
2. Composite attribute
3. Multivalued attribute
4. Derived attribute

1. KEY ATTRIBUTE:
A key attribute can uniquely identify an entity from an entity set. For example, student roll number can
uniquely identify a student from a set of students. Key attribute is represented by oval same as other attributes
however the text of key attribute is underlined.

2. COMPOSITE ATTRIBUTE:
14 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

An attribute that is a combination of other attributes is known as composite attribute. For example, In student
entity, the student address is a composite attribute as an address is composed of other attributes such as pin
code, state, country.

3. MULTIVALUED ATTRIBUTE:

An attribute that can hold multiple values is known as multivalued attribute. It is represented with double
ovals in an ER Diagram. For example – A person can have more than one phone numbers so the phone number
attribute is multivalued.

4. DERIVED ATTRIBUTE:

A derived attribute is one whose value is dynamic and derived from another attribute. It is represented by dashed
oval in an ER Diagram. For example – Person age is a derived attribute as it changes over time and can be derived
from another attribute (Date of birth).

E-R diagram with multivalued and derived attributes:

3. RELATIONSHIP

A relationship is represented by diamond shape in ER diagram, it shows the relationship among entities. There
are four types of relationships:

1. One to One
2. One to Many
3. Many to One
4. Many to Many

1. ONE TO ONE RELATIONSHIP

When a single instance of an entity is associated with a single instance of another entity then it is called one to
one relationship. For example, a person has only one passport and a passport is given to one person.
15 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

2. ONE TO MANY RELATIONSHIP

When a single instance of an entity is associated with more than one instances of another entity then it is called
one to many relationships. For example – a customer can place many orders but a order cannot be placed by
many customers.

3. MANY TO ONE RELATIONSHIP

When more than one instances of an entity is associated with a single instance of another entity then it is called
many to one relationship. For example – many students can study in a single college but a student cannot study
in many colleges at the same time.

4. MANY TO MANY RELATIONSHIP

When more than one instances of an entity is associated with more than one instances of another entity then it
is called many to many relationships. For example, a can be assigned to many projects and a project can be
assigned to many students.

TOTAL PARTICIPATION OF AN ENTITY SET

A Total participation of an entity set represents that each entity in entity set must have at least one relationship
in a relationship set. For example: In the below diagram each college must have at-least one associated Student.
16 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

HISTORY OF ER MODELS

ER diagrams are a visual tool which is helpful to represent the ER model. It was proposed by Peter Chen in 1971
to create a uniform convention which can be used for relational database and network. He aimed to use an ER
model as a conceptual modeling approach.

Entity relationship diagram 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.

Sample ER Diagram
17 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

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

● 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:

● Entities
● Attributes
● 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.
18 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

WHAT IS ENTITY?

A real-world thing either living or non-living that is easily recognizable and nonrecognizable. 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

Notation of an Entity

ENTITY SET:

Student

An entity set is a group of similar kind of entities. It may contain entities with attribute sharing similar values.
Entities are represented by their properties, which also called attributes. All attributes have their separate
values. For example, a student entity may have a name, age, class, as attributes.

RELATIONSHIP

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

Entities take part in relationships. We can often identify relationships with verbs or verb phrases.

WEAK ENTITIES

A weak entity is a type of entity which doesn't have its key attribute. It can be identified uniquely by
considering the primary key of another entity. For that, weak entity sets need to have participation.
19 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

In aboe example, "Trans No" is a discriminator within a group of transactions in an ATM.

Strong Entity Set Weak Entity Set

Strong entity set always has a primary key. It does not have enough attributes to build a primary key.

It is represented by a rectangle symbol. It is represented by a double rectangle symbol.

It contains a Primary key represented by the It contains a Partial Key which is represented by a dashed
underline symbol. underline symbol.

The member of a strong entity set is called as The member of a weak entity set called as a subordinate
dominant entity set. entity set.

Primary Key is one of its attributes which helps to In a weak entity set, it is a combination of primary key and
identify its member. partial key of the strong entity set.

In the ER diagram the relationship between two The relationship between one strong and a weak entity
strong entity set shown by using a diamond set shown by using the double diamond symbol.
symbol.

The connecting line of the strong entity set with the The line connecting the weak entity set for identifying
relationship is single. relationship is double.

ATTRIBUTES
It is a single-valued property of either an entity-type or a relationship-type. An attribute is represented by an
Ellipse
20 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Types of Attributes Description

Simple attribute Simple attributes can't be divided any further. For example, a student's contact
number. It is also called an atomic value.

Composite attribute It is possible to break down composite attribute. For example, a student's full name
may be further divided into first name, second name, and last name.

Derived attribute This type of attribute does not include in the physical database. However, their values
are derived from other attributes present in the database. For example, age should
not be stored directly. Instead, it should be derived from the DOB of that employee.

Multivalued attribute Multivalued attributes can have more than one values. For example, a student can
have more than one mobile number, email address, etc.

CARDINALITY
Defines the numerical attributes of the relationship between two entities or entity sets.
Different types of cardinal relationships are:

● One-to-One Relationships
● One-to-Many Relationships
● May to One Relationships
● Many-to-Many Relationships
21 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

1.One-to-one:
One entity from entity set X can be associated with at most one entity of entity set Y and vice versa.
Example: One student can register for numerous courses. However, all those courses have a single line back to that one
student.

2.One-to-many:
One entity from entity set X can be associated with multiple entities of entity set Y, but an entity from entity set
Y can be associated with at least one entity.
For example, one class is consisting of multiple students.

3. Many to One
More than one entity from entity set X can be associated with at most one entity of entity set Y. However, an
entity from entity set Y may or may not be associated with more than one entity from entity set X.
For example, many students belong to the same class.
22 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

4. Many to Many:
One entity from X can be associated with more than one entity from Y and vice versa.
For example, Students as a group are associated with multiple faculty members, and faculty members can be associated
with multiple students.

ER- DIAGRAM NOTATIONS

ER- Diagram is a visual representation of data that describe how data is related to each other.

● Rectangles: This symbol represent entity types


● Ellipses: Symbol represent attributes
● Diamonds: This symbol represents relationship types
● Lines: It links attributes to entity types and entity types with other relationship types
● Primary key: attributes are underlined
● Double Ellipses: Represent multi-valued attributes

STEPS TO CREATE AN ERD

Following are the steps to create an ERD.


23 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

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
● 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

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.

Entity Primary Key Attribute


24 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Student Student_ID StudentName

Professor Employee_ID ProfessorName

Course_ID CourseName

STEP 5) CREATE THE ERD

A more modern representation of ERD Diagram

BEST PRACTICES FOR DEVELOPING EFFECTIVE ER DIAGRAMS

● Eliminate any redundant entities or relationships


● You need to make sure that all your entities and relationships are properly labeled
● There may be various valid approaches to an ER diagram. You need to make sure that the ER diagram supports all
the data you need to store
● You should assure that each entity only appears a single time in the ER diagram
● Name every relationship, entity, and attribute are represented on your diagram
● Never connect relationships to each other
● You should use colors to highlight important portions of the ER diagram

SUMMARY

● The ER model is a high-level data model diagram


● ER diagrams are a visual tool which is helpful to represent the ER model
● Entity relationship diagram displays the relationships of entity set stored in a database
● ER diagrams help you to define terms related to entity relationship modeling
● ER model is based on three basic concepts: Entities, Attributes & Relationships
● An entity can be place, person, object, event or a concept, which stores data in the database
● Relationship is nothing but an association among two or more entities
● A weak entity is a type of entity which doesn't have its key attribute
● It is a single-valued property of either an entity-type or a relationship-type
● It helps you to defines the numerical attributes of the relationship between two entities or entity sets
● ER- Diagram is a visual representation of data that describe how data is related to each other
● While Drawing ER diagram you need to make sure all your entities and relationships are properly labeled.
25 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

SEQUENCE DIAGRAM TUTORIAL


A sequence diagram describes an interaction among a set of objects participated in a collaboration (or scenario),
arranged in a chronological order; it shows the objects participating in the interaction by their "lifelines" and the
messages that they send to each other.

WHAT IS A SEQUENCE DIAGRAM IN UML?

UML Sequence diagrams are interaction diagrams that detail how operations are carried out. As sequence
diagrams can be used to capture the interaction between objects in the context of a collaboration, one of the
primary uses of sequence diagrams is in the transition from requirements expressed as use cases to the next and
more formal level of refinement. Use cases are often refined into one or more sequence diagrams.

Sequence diagrams are time focus and they show the order of the interaction visually by using the vertical axis
of the diagram to represent time what messages are sent and when.

Sequence Diagrams captures interaction in different level of granularity:

 high-level interactions between user of the system and the system, between the system and other systems,
or between subsystems (sometimes known as system sequence diagrams)
 the interaction that takes place in a collaboration that either realizes a use case or an operation (instance
diagrams or generic diagrams)
 Represent objects interact in (Model, View / Controller) MVC pattern of software framework

SEQUENCE DIAGRAM NOTATIONS


LIFELINE
A lifeline represents an individual participant in the Interaction.
26 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

ACTOR
An Actor a type of role played by an entity that interacts with the subject (e.g., by exchanging signals and data).
An actor can also be an external to the subject (i.e., in the sense that an instance of an actor is not a part of the
instance of its corresponding subject). They typically represent roles played by human users, external hardware,
or other subjects.

Note That:

 An actor does not necessarily represent a specific physical entity but merely a particular role of some entity
 A person may play the role of several different actors and, conversely, a given actor may be played by multiple
different persons.

ACTIVATION
An activation is represented by a thin rectangle on a lifeline) represents the period during which an element is
performing an operation. The top and the bottom of the of the rectangle are aligned with the initiation and the
completion time respectively

MESSAGES

CALL MESSAGE
A call message defines a particular communication between lifelines of an interaction, which represents an
invocation of operation of target lifeline.

RETURN MESSAGE
A return message defines a particular communication between lifelines of an interaction, which represents the
pass of information back to the caller of a corresponded former message.
27 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

SELF MESSAGE
A self-message defines a particular communication between lifelines of an interaction, which represents the
invocation of message of the same lifeline.

RECURSIVE MESSAGE
A recursive message defines a particular communication between lifelines of an interaction, which represents the
invocation of message of the same lifeline. It's target points to an activation on top of the activation where the
message was invoked from.

CREATE MESSAGE
A create message defines a particular communication between lifelines of an interaction, which represents the
instantiation of (target) lifeline.

DESTROY MESSAGE
A destroy message defines a particular communication between lifelines of an interaction, which represents the
request of destroying the lifecycle of target lifeline.

DURATION MESSAGE
A duration message defines a particular communication between lifelines of an interaction, which shows the
distance between two-time instants for a message invocation.
28 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

NOTE
A note (comment) gives the ability to attach various remarks to elements. A comment carries no semantic force,
but may contain information that is useful to a modeler.

WHEN TO DRAW SEQUENCE DIAGRAM?

 Model high-level interaction between active objects in a system


 Model the interaction between object instances within a collaboration that realizes a use case
 Model the interaction between objects within a collaboration that realizes an operation
 Either model generic interactions (showing all possible paths through the interaction) or specific instances of
a interaction (showing just one path through the interaction)

HOW TO DRAW A SEQUENCE DIAGRAM?

 Identify a set of objects that will participate in the general collaboration (or use case scenario)
 If you derive the sequence diagram based on a scenario of a use case, select the normal scenarios first
 You should know the primary actor(s) who activates the use case
 Consider the first point of the scenario (or if you get it from the first point of the flow of event of a use case)
 Consider what the system needs to be done in order to response to the actor, when the actor send the
message to the system
 What the system needs to be handled before the return message response back from the system?
 E.g., A customer inserted an ATM card to the machine, the system will display "input pin number" in the
normal scenario, right?
 Guess, what will to be handled inside the ADM by a set of objects at the "back" of the system? Something
like, read and verify the ATM card (card reader), read the card information of the card holder (by the bank)
and ask for the pin, or, return "invalid card type, insert another card", and etc.
 By this way, you will identify the candidate objects and operations of the target application for that particular
scenario and you can also use this information as a basis to derive the class diagram incrementally.
 Repeat each of the point of the scenario (or flow of event) and until you complete all the points in the
scenario.

You can also:

Draw a set of corresponding sequence diagrams for the exception or alternative scenarios.

SEQUENCE DIAGRAM EXAMPLES

The sequence diagram example below shows the interactions between a user and a ticket booking system in
booking a seat. It consists of mainly four parts: The actor, which is the user, the boundary object ‘interface', the
controller object ‘main controller' and two entity objects routes and route.
29 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

The sequence diagram example below shows a patient admission process. It shows the use of timing and duration
constraint.

The sequence diagram example shows how recursive message can be used in interaction modeling.
30 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

CLASS?
A Class is a blueprint that is used to create Object. The Class defines what object can do.

WHAT IS CLASS DIAGRAM?

Class Diagram gives the static view of an application. A class diagram describes the types of objects in the system
and the different types of relationships that exist among them. This modeling method can run with almost all
Object-Oriented Methods. A class can refer to another class. A class can have its objects or may inherit from
other classes.

UML Class Diagram gives an overview of a software system by displaying classes, attributes, operations, and their
relationships. This Diagram includes the class name, attributes, and operation in separate designated
compartments.

Class Diagram helps construct the code for the software application development.

BENEFITS OF CLASS DIAGRAM

 Class Diagram Illustrates data models for even very complex information systems
 It provides an overview of how the application is structured before studying the actual code. This can easily
reduce the maintenance time
 It helps for better understanding of general schematics of an application.
 Allows drawing detailed charts which highlights code required to be programmed
 Helpful for developers and other stakeholders.

ESSENTIAL ELEMENTS OF A UML CLASS DIAGRAM

Essential elements of UML class diagram are:

1. Class Name
2. Attributes
3. Operations
31 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

CLASS NAME

The name of the class is only needed in the graphical representation of the class. It appears in the topmost
compartment. A class is the blueprint of an object which can share the same relationships, attributes, operations,
& semantics. The class is rendered as a rectangle, including its name, attributes, and operations in sperate
compartments.

Following rules must be taken care of while representing a class:

1. A class name should always start with a capital letter.


2. A class name should always be in the center of the first compartment.
3. A class name should always be written in bold format.
4. An abstract class name should be written in italics format.

ATTRIBUTES:
An attribute is named property of a class which describes the object being modeled. In the class diagram, this
component is placed just below the name-compartment.

A derived attribute is computed from other attributes. For example, an age of the student can be easily computed
from his/her birth date.
32 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Attributes characteristics

 The attributes are generally written along with the visibility factor.
 Public, private, protected and package are the four visibilities which are denoted by +, -, #, or ~ signs
respectively.
 Visibility describes the accessibility of an attribute of a class.
 Attributes must have a meaningful name that describes the use of it in a class.

RELATIONSHIPS

There are mainly three kinds of relationships in UML:

1. Dependencies
2. Generalizations
3. Associations

Dependency
A dependency means the relation between two or more classes in which a change in one may force changes in
the other. However, it will always create a weaker relationship. Dependency indicates that one class depends on
another.

In the following example, Student has a dependency on College

Generalization:
A generalization helps to connect a subclass to its superclass. A sub-class is inherited from its superclass.
Generalization relationship can't be used to model interface implementation. Class diagram allows inheriting
from multiple super classes.

In this example, the class Student is generalized from Person Class.

Association:
This kind of relationship represents static relationships between classes A and B. For example; an employee works
for an organization.

Here are some rules for Association:

 Association is mostly verb or a verb phrase or noun or noun phrase.


 It should be named to indicate the role played by the class attached at the end of the association path.
 Mandatory for reflexive associations

In this example, the relationship between student and college is shown which is studies.
33 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Multiplicity

A multiplicity is a factor associated with an attribute. It specifies how many instances of attributes are created
when a class is initialized. If a multiplicity is not specified, by default one is considered as a default multiplicity.

Let's say that that there are 100 students in one college. The college can have multiple students.

Aggregation
Aggregation is a special type of association that models a whole- part relationship between aggregate and its
parts.

For example, the class college is made up of one or more student. In aggregation, the contained classes are never
totally dependent on the lifecycle of the container. Here, the college class will remain even if the student is not
available.

Composition:

The composition is a special type of aggregation which denotes strong ownership between two classes when
one class is a part of another class.

For example, if college is composed of classes student. The college could contain many students, while each
student belongs to only one college. So, if college is not functioning all the students also removed.

AGGREGATION VS. COMPOSITION

Aggregation Composition

Aggregation indicates a relationship where the Composition display relationship where the child will never
child can exist separately from their parent class. exist independent of the parent. Example: House (parent)
Example: Automobile (Parent) and Car (Child). So, and Room (child). Rooms will never separate into a House.
if you delete the Automobile, the child Car still
exist.
34 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

ABSTRACT CLASSES

It is a class with an operation prototype, but not the implementation. It is also possible to have an abstract class
with no operations declared inside of it. An abstract is useful for identifying the functionalities across the classes.
Let us consider an example of an abstract class. Suppose we have an abstract class called as a motion with a
method or an operation declared inside of it. The method declared inside the abstract class is called a move ().

This abstract class method can be used by any object such as a car, an animal, robot, etc. for changing the current
position. It is efficient to use this abstract class method with an object because no implementation is provided
for the given function. We can use it in any way for multiple objects.

In UML, the abstract class has the same notation as that of the class. The only difference between a class and an
abstract class is that the class name is strictly written in an italic font.

An abstract class cannot be initialized or instantiated.

Abstract Class Notation

In the above abstract class notation, there is the only a single abstract method which can be used by multiple
objects of classes.

EXAMPLE OF UML CLASS DIAGRAM

Creating a class diagram is a straightforward process. It does not involve many technicalities. Here, is an example:

ATMs system is very simple as customers need to press some buttons to receive cash. However, there are multiple
security layers that any ATM system needs to pass. This helps to prevent fraud and provide cash or need details
to banking customers.

Below given is a UML Class Diagram example:


35 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

CLASS DIAGRAM IN SOFTWARE DEVELOPMENT LIFECYCLE

Class diagrams can be used in various software development phases. It helps in modeling class diagrams in three
different perspectives.

1. Conceptual perspective: Conceptual diagrams are describing things in the real world. You should draw a
diagram that represents the concepts in the domain under study. These concepts related to class and it is always
language-independent.

2. Specification perspective: Specification perspective describes software abstractions or components with


specifications and interfaces. However, it does not give any commitment to specific implementation.

3. Implementation perspective: This type of class diagrams is used for implementations in a specific language
or application. Implementation perspective, use for software implementation.

BEST PRACTICES OF DESIGNING OF THE CLASS DIAGRAM

Class diagrams are the most important UML diagrams used for software application development. There are
many properties which should be considered while drawing a Class Diagram. They represent various aspects of
a software application.

Here, are some points which should be kept in mind while drawing a class diagram:

 The name given to the class diagram must be meaningful. Moreover, It should describe the real aspect
of the system.
 The relationship between each element needs to be identified in advance.
 The responsibility for every class needs to be identified.
 For every class, minimum number of properties should be specified. Therefore, unwanted properties can
easily make the diagram complicated.
36 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

 User notes should be included whenever you need to define some aspect of the diagram. At the end of
the drawing, it must be understandable for the software development team.
 Lastly, before creating the final version, the diagram needs to be drawn on plain paper. Moreover, It
should be reworked until it is ready for final submission.

CONCLUSION

 UML is the standard language for specifying, designing, and visualizing the artifacts of software systems
 A class is a blueprint for an object
 A class diagram describes the types of objects in the system and the different kinds of relationships which
exist among them
 It allows analysis and design of the static view of a software application
 Class diagrams are most important UML diagrams used for software application development
 Essential elements of UML class diagram are 1) Class 2) Attributes 3) Relationships
 Class Diagram provides an overview of how the application is structured before studying the actual code. It
certainly reduces the maintenance time
 The class diagram is useful to map object-oriented programming languages like Java, C++, Ruby, Python,
etc.

Regards,

Muhammad Babar Ali


Information Technology - Dept

Shakarganj Food Products Limited


Address: 4-KM Lahore Road Jaranwala, Faisalabad, Punjab
HO: E-Floor, IT Tower, 73-E/1 Hali Road, Gulberg III, Lahore
DIR:+92 300 843 5958|300 760 0069|URL: www.sfpl.com.pk
37 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

DBMS / SQL

1. What is DBMS?
A Database Management System (DBMS) is a program that controls creation, maintenance and use of a
database. DBMS can be termed as File Manager that manages data in a database rather than saving it in
file systems.

2. What is RDBMS?
RDBMS stands for Relational Database Management System. RDBMS store the data into the collection of
tables, which is related by common fields between the columns of the table. It also provides relational
operators to manipulate the data stored into the tables.

Example: SQL Server.

3. What is SQL?
SQL stands for Structured Query Language, and it is used to communicate with the Database. This is a
standard language used to perform tasks such as retrieval, updation, insertion and deletion of data from a
database. Standard SQL Commands are Select.

4. What is a Database?
Database is nothing but an organized form of data for easy access, storing, retrieval and managing of data.
This is also known as structured form of data which can be accessed in many ways.
Example: School Management Database, Bank Management Database.

5. What are tables and Fields?


A table is a set of data that are organized in a model with Columns and Rows. Columns can be categorized
as vertical, and Rows are horizontal. A table has specified number of columns called fields but can have
any number of rows which is called record.

Example:.
Table: Employee.
Field: Emp ID, Emp Name, Date of Birth.
Data: 201456, David, 11/15/1960.

6. What is a primary key?


A primary key is a combination of fields which uniquely specify a row. This is a special kind of unique key,
and it has implicit NOT NULL constraint. It means, Primary key values cannot be NULL.

7. What is a unique key?


A Unique key constraint uniquely identified each record in the database. This provides uniqueness for the
column or set of columns. A Primary key constraint has automatic unique constraint defined on it. But not,
in the case of Unique Key. There can be many unique constraints defined per table, but only one Primary
key constraint defined per table.

8. What is a foreign key?


A foreign key is one table which can be related to the primary key of another table. Relationship needs to
be created between two tables by referencing foreign key with the primary key of another table.

9. What is a join?
This is a keyword used to query data from more tables based on the relationship between the fields of the
tables. Keys play a major role when JOINs are used.

10. What are the types of join and explain each?


There are various types of join which can be used to retrieve data and it depends on the relationship
between tables.

 Inner Join.

Inner join return rows when there is at least one match of rows between the tables.

 Right Join.
38 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Right join return rows which are common between the tables and all rows of right-hand side table.
Simply, it returns all the rows from the right-hand side table even though there are no matches in the left-
hand side table.

 Left Join.

Left join return rows which are common between the tables and all rows of Left-hand side table. Simply,
it returns all the rows from Left hand side table even though there are no matches in the Right-hand side
table.

 Full Join.

Full join return rows when there are matching rows in any one of the tables. This means, it returns all the
rows from the left-hand side table and all the rows from the right hand side table.

11. What is normalization?


Normalization is the process of minimizing redundancy and dependency by organizing fields and table of
a database. The main aim of Normalization is to add, delete or modify field that can be made in a single
table.

12. What is Denormalization.


De-Normalization is a technique used to access the data from higher to lower normal forms of database. It
is also process of introducing redundancy into a table by incorporating data from the related tables.

13. What are all the different normalizations?


The normal forms can be divided into 5 forms, and they are explained below -.

 First Normal Form (1NF):.

This should remove all the duplicate columns from the table. Creation of tables for the related data and
identification of unique columns.

 Second Normal Form (2NF):.

Meeting all requirements of the first normal form. Placing the subsets of data in separate tables and
Creation of relationships between the tables using primary keys.

 Third Normal Form (3NF):.

This should meet all requirements of 2NF. Removing the columns which are not dependent on primary key
constraints.

 Fourth Normal Form (4NF):.

Meeting all the requirements of third normal form and it should not have multi- valued dependencies.

14. What is a View?


A view is a virtual table which consists of a subset of data contained in a table. Views are not virtually
present, and it takes less space to store. View can have data of one or more tables combined, and it is
depending on the relationship.

15. What is an Index?


An index is performance tuning method of allowing faster retrieval of records from the table. An index
creates an entry for each value and it will be faster to retrieve data.

16. What are all the different types of indexes?


There are three types of indexes -.

 Unique Index.

This indexing does not allow the field to have duplicate values if the column is unique indexed. Unique
index can be applied automatically when primary key is defined.
39 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

 Clustered Index.

This type of index reorders the physical order of the table and search based on the key values. Each table
can have only one clustered index.

 NonClustered Index.

NonClustered Index does not alter the physical order of the table and maintains logical order of data. Each
table can have 999 nonclustered indexes.

17. What is a Cursor?


A database Cursor is a control which enables traversal over the rows or records in the table. This can be
viewed as a pointer to one row in a set of rows. Cursor is very much useful for traversing such as retrieval,
addition and removal of database records.

18. What is a relationship and what are they?


Database Relationship is defined as the connection between the tables in a database. There are various
data basing relationships, and they are as follows:
 One to One Relationship.
 One to Many Relationship.
 Many to One Relationship.
 Self-Referencing Relationship.

19. What is a query?


A DB query is a code written in order to get the information back from the database. Query can be
designed in such a way that it matched with our expectation of the result set. Simply, a question to the
Database.

20. What is subquery?


A subquery is a query within another query. The outer query is called as main query, and inner query is
called subquery. Subquery is always executed first, and the result of subquery is passed on to the main
query.

21. What are the types of subquery?


There are two types of subquery – Correlated and Non-Correlated.
A correlated subquery cannot be considered as independent query, but it can refer the column in a table
listed in the FROM the list of the main query.
A Non-Correlated sub query can be considered as independent query and the output of subquery are
substituted in the main query.

22. What is a stored procedure?


Stored Procedure is a function consists of many SQL statement to access the database system. Several
SQL statements are consolidated into a stored procedure and execute them whenever and wherever
required.

23. What is a trigger?


A DB trigger is a code or programs that automatically execute with response to some event on a table or
view in a database. Mainly, trigger helps to maintain the integrity of the database.
Example: When a new student is added to the student database, new records should be created in the
related tables like Exam, Score and Attendance tables.

24. What is the difference between DELETE and TRUNCATE commands?


DELETE command is used to remove rows from the table, and WHERE clause can be used for conditional
set of parameters. Commit and Rollback can be performed after delete statement.
TRUNCATE removes all rows from the table. Truncate operation cannot be rolled back.

25. What are local and global variables and their differences?
40 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Local variables are the variables which can be used or exist inside the function. They are not known to
the other functions and those variables cannot be referred or used. Variables can be created whenever
that function is called.

Global variables are the variables which can be used or exist throughout the program. Same variable
declared in global cannot be used in functions. Global variables cannot be created whenever that function
is called.

26. What is a constraint?


Constraint can be used to specify the limit on the data type of table. Constraint can be specified while
creating or altering the table statement. Sample of constraint are.
 NOT NULL.
 CHECK.
 DEFAULT.
 UNIQUE.
 PRIMARY KEY.
 FOREIGN KEY.

27. What is data Integrity?


Data Integrity defines the accuracy and consistency of data stored in a database. It can also define integrity
constraints to enforce business rules on the data when it is entered into the application or database.

28. What is Auto Increment?


Auto increment keyword allows the user to create a unique number to be generated when a new record is
inserted into the table. AUTO INCREMENT keyword can be used in Oracle and IDENTITY keyword can be
used in SQL SERVER. Mostly this keyword can be used whenever PRIMARY KEY is used.

29. What is the difference between Cluster and Non-Cluster Index?


Clustered index is used for easy retrieval of data from the database by altering the way that the records are
stored. Database sorts out rows by the column which is set to be clustered index. A non-clustered index
does not alter the way it was stored but creates a complete separate object within the table. It points back
to the original table rows after searching.

30. What is Datawarehouse?


Datawarehouse is a central repository of data from multiple sources of information. Those data are
consolidated, transformed and made available for the mining and online processing. Warehouse data have
a subset of data called Data Marts.

31. What is Self-Join?


Self-join is set to be query used to compare to itself. This is used to compare values in a column with other
values in the same column in the same table. ALIAS ES can be used for the same table comparison.

32. What is Cross-Join?


Cross join defines as Cartesian product where number of rows in the first table multiplied by number of
rows in the second table. If suppose, WHERE clause is used in cross join then the query will work like an
INNER JOIN.

33. What is user defined functions?


User defined functions are the functions written to use that logic whenever required. It is not necessary to
write the same logic several times. Instead, function can be called or executed whenever needed.

34. What are all types of user defined functions?


Three types of user defined functions are.
 Scalar Functions.
 Inline Table valued functions.
 Multi statement valued functions.
Scalar returns unit, variant defined the return clause. Other two types return table as a return.
41 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

35. What is collation?


Collation is defined as set of rules that determine how character data can be sorted and compared. This can
be used to compare A and, other language characters and also depends on the width of the characters.
ASCII value can be used to compare these character data.

36. What are all different types of collation sensitivity?


Following are different types of collation sensitivity -.
 Case Sensitivity – A and a and B and b.
 Accent Sensitivity.
 Kana Sensitivity – Japanese Kana characters.
 Width Sensitivity – Single byte character and double byte character.

37. Advantages and Disadvantages of Stored Procedure?


Stored procedure can be used as a modular programming – means create once, store and call for several
times whenever required. This supports faster execution instead of executing multiple queries. This
reduces network traffic and provides better security to the data.
Disadvantage is that it can be executed only in the Database and utilizes more memory in the database
server.

38. What is Online Transaction Processing (OLTP)?


Online Transaction Processing (OLTP) manages transaction-based applications which can be used for data
entry, data retrieval and data processing. OLTP makes data management simple and efficient. Unlike OLAP
systems goal of OLTP systems is serving real-time transactions.
Example – Bank Transactions on a daily basis.

39. What is CLAUSE?


SQL clause is defined to limit the result set by providing condition to the query. This usually filters some
rows from the whole set of records.
Example – Query that has WHERE condition
Query that has HAVING condition.

40. What is recursive stored procedure?


A stored procedure which calls by itself until it reaches some boundary condition. This recursive function
or procedure helps programmers to use the same set of code any number of times.

41. What is Union, minus and Interact commands?


UNION operator is used to combine the results of two tables, and it eliminates duplicate rows from the
tables.
MINUS operator is used to return rows from the first query but not from the second query. Matching
records of first and second query and other rows from the first query will be displayed as a result set.
INTERSECT operator is used to return rows returned by both the queries.

42. What is an ALIAS command?


ALIAS name can be given to a table or column. This alias name can be referred in WHERE clause to identify
the table or column.
Example-.
Select st.StudentID, Ex.Result from student st, Exam as Ex where st.studentID = Ex. StudentID
Here, st refers to alias name for student table and Ex refers to alias name for exam table.

43. What is the difference between TRUNCATE and DROP statements?


TRUNCATE removes all the rows from the table, and it cannot be rolled back. DROP command removes a
table from the database and operation cannot be rolled back.

44. What are aggregate and scalar functions?


Aggregate functions are used to evaluate mathematical calculation and return single values. This can be
calculated from the columns in a table. Scalar functions return a single value based on the input value.
Example -.
Aggregate – max(), count - Calculated with respect to numeric.
Scalar – UCASE(), NOW() – Calculated with respect to strings.

45. How can you create an empty table from an existing table?

Example will be -.
42 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

Select * into studentcopy from student where 1=2


Here, we are copying student table to another table with the same structure with no rows copied.

46. How to fetch common records from two tables?


Common records result set can be achieved by -.
Select studentID from student. <strong>INTERSECT </strong> Select StudentID from Exam.

47. How to fetch alternate records from a table?


Records can be fetched for both Odd and Even row numbers -.
To display even numbers-.
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=0
To display odd numbers-.
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=1
from (Select rowno, studentId from student) where mod(rowno,2)=1.[/sql]

48. How to select unique records from a table?


Select unique records from a table by using DISTINCT keyword.
Select DISTINCT StudentID, StudentName from Student.

49. What is the command used to fetch first 5 characters of the string?

There are many ways to fetch first 5 characters of the string -.


Select SUBSTRING(StudentName,1,5) as studentname from student
Select LEFT(Studentname,5) as studentname from student

50. Which operator is used in query for pattern matching?


LIKE operator is used for pattern matching, and it can be used as -.
1. % - Matches zero or more characters.
2. _(Underscore) – Matching exactly one character.
Example -.
Select * from Student where studentname like 'a%'
Select * from Student where studentname like 'ami_'

Regards,

Muhammad Babar Ali


Information Technology - Dept

Shakarganj Food Products Limited


Address: 4-KM Lahore Road Jaranwala, Faisalabad, Punjab
HO: E-Floor, IT Tower, 73-E/1 Hali Road, Gulberg III, Lahore
DIR:+92 300 843 5958|300 760 0069|URL: www.sfpl.com.pk
43 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

SQL COMMANDS
SQL is a programming language for Relational Databases. It is designed over relational algebra and tuple
relational calculus. SQL comes as a package with all major distributions of RDBMS.

SQL comprises both data definition and data manipulation languages. Using the data definition
properties of SQL, one can design and modify database schema, whereas data manipulation properties
allows SQL to store and retrieve data from database.

SQL Commands:
The standard SQL commands to interact with relational databases are CREATE, SELECT, INSERT,
UPDATE, DELETE and DROP. These commands can be classified into groups based on their nature:

DDL - Data Definition Language:


ALTER Modifies an existing database object, such as a table.

DROP Deletes an entire table, a view of a table or other object in the database.

CREATE Creates a new table, a view of a table, or other object in database

DML - Data Manipulation Language:


Command Description

SELECT Retrieves certain records from one or more tables


INSERT Creates a record

UPDATE Modifies records

DELETE Deletes records

DCL - Data Control Language:


Command Description

GRANT Gives a privilege to user


REVOKE Takes back privileges granted from user
Data Definition Language

The DDL section is used for creating database objects, such as tables. In practice, people often use a GUI
for creating tables and so on, so it is less common to hand-write DDL statements than it used to be.
SQL uses the following set of commands to define database schema

CREATE
Creates new databases, tables and views from RDBMS.

CREATE DATABASE databasename;

CREATE TABLE table_name (


column1 datatype,
column2 datatype,
column3 datatype,
....
);
44 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

DROP
Drops commands, views, tables, and databases from RDBMS. For example−

DROP DATABASE databasename;


DROP TABLE table_name;

ALTER
Modifies database schema.

ALTER TABLE table_name


ADD column_name datatype;

Difference between Drop, Truncate and Delete

DELETE
DELETE removes some rows if WHERE clause is used

DROP

Removes a table from the database. Table structures, indexes, privileges, constraints will also be
removed.

TRUNCATE
It Removes all rows from a table, but the table structures and its columns, constraints, indexes remain.

Data Manipulation Language


The DML section is used to manipulate the data such as querying it. While is also common to use a query
builder to create queries, people do still hand-craft DML statements, such as queries.

SQL is equipped with data manipulation language (DML). DML modifies the database instance by inserting,
updating and deleting its data. DML is responsible for all froms data modification in a database. SQL contains
the following set of commands in its DML section −

 SELECT/FROM/WHERE
 INSERT INTO/VALUES
 UPDATE/SET/WHERE
 DELETE FROM/WHERE

These basic constructs allow database programmers and users to enter data and information into the
database and retrieve efficiently using a number of filter options.

SELECT/FROM/WHERE
SELECT − This is one of the fundamental query commands of SQL. It is similar to the projection
operation of relational algebra. It selects the attributes based on the condition described by WHERE clause.

FROM − This clause takes a relation name as an argument from which attributes are to be
selected/projected. In case more than one relation names are given, this clause corresponds to Cartesian
product.

WHERE − This clause de ines predicate or conditions, which must match in order to qualify the
attributes to be projected.
SELECT column1, column2, ...
FROM table_name;

SELECT column1, column2, ...


FROM table_name
WHERE condition;
45 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

INSERT INTO/VALUES
This command is used for inserting values into the rows of a table (relation). Syntax−
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

INSERT INTO table_name


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

UPDATE/SET/WHERE
This command is used for updating or modifying the values of columns in a table (relation).

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

DELETE/FROM/WHERE
This command is used for removing one or more rows from a table (relation).

DELETE FROM table_name WHERE condition;

CRUD Operations / DML SQL Queries

CRUD (Create, Read, Update, and Delete) operation on a database


Operation SQL
Create INSERT
Read (Retrieve) SELECT
Update (Modify) UPDATE
Delete (Destroy) DELETE

MySQL Database Connection

<?php
$conn = mysql_connect("localhost", "root", "");
mysql_select_db("testdb", $conn);
?>

Here
localhost is host name
root is user name
“” password is empty
testdb is database name

QUERY TO INSERT DATA IN TABLE EMPLOYEE:


$sql = mysql_query("INSERT INTO employee(empid,name,address,dob,sal,timeIn)
VALUES('$_POST[empid]','$_POST[name]','$_POST[address]','$_POST[dob]','$_POST
[sal]','$_POST[timeIn]')");

QUERY TO UPDATE DATA IN TABLE EMPLOYEE


$sql = mysql_query("UPDATE employee set
name='$_POST[name]',address='$_POST[address]',dob='$_POST[dob]',sal='$_POST[sal
]',timeIn='$_POST[timeIn]' where empid=$_POST[hiddenID]");

QUERY TO DELETE DATA FROM TABLE EMPLOYEE


46 | M C 1 0 0 4 0 2 1 8 0 – M U H A M M A D B A B A R

$sql = mysql_query("delete from employee where empid='$_POST[hiddenID]'") or


die(mysql_error());

QUERY TO SELECT DATA FROM TABLE EMPLOYEE


$sql = mysql_query("select * from employee where empid=$search") or die(mysql_error());

Regards,

Muhammad Babar Ali


Information Technology - Dept

Shakarganj Food Products Limited


Address: 4-KM Lahore Road Jaranwala, Faisalabad, Punjab
HO: E-Floor, IT Tower, 73-E/1 Hali Road, Gulberg III, Lahore
DIR:+92 300 843 5958|300 760 0069|URL: www.sfpl.com.pk

You might also like