Professional Documents
Culture Documents
Database is a collection of related data and data is a collection of facts and figures that can be processed to produce
information.
Mostly data represents recordable facts. Data aids in producing information, which is based on facts. For example, if
we have data about marks obtained by all students, we can then conclude about toppers and average marks.
A database management system stores data in such a way that it becomes easier to retrieve, manipulate, and
produce information.
Characteristics
Traditionally, data was organized in file formats. DBMS was a new concept then, and all the research was done to
make it overcome the deficiencies in traditional style of data management. A modern DBMS has the following
characteristics −
● Real-world entity − A modern DBMS is more realistic and uses real-world entities to design its architecture.
It uses the behavior and attributes too. For example, a school database may use students as an entity and
their age as an attribute.
● Relation-based tables − DBMS allows entities and relations among them to form tables. A user can
understand the architecture of a database just by looking at the table names.
● Isolation of data and application − A database system is entirely different than its data. A database is an
active entity, whereas data is said to be passive, on which the database works and organizes. DBMS also
stores metadata, which is data about data, to ease its own process.
● Less redundancy − DBMS follows the rules of normalization, which splits a relation when any of its
attributes is having redundancy in values. Normalization is a mathematically rich and scientific process that
reduces data redundancy.
● Consistency − Consistency is a state where every relation in a database remains consistent. There exist
methods and techniques, which can detect attempt of leaving database in inconsistent state. A DBMS can
provide greater consistency as compared to earlier forms of data storing applications like file-processing
systems.
● Query Language − DBMS is equipped with query language, which makes it more efficient to retrieve and
manipulate data. A user can apply as many and as different filtering options as required to retrieve a set of
data. Traditionally it was not possible where file-processing system was used.
● ACID Properties − DBMS follows the concepts of Atomicity, Consistency, Isolation, and Durability (normally
shortened as ACID). These concepts are applied on transactions, which manipulate data in a database.
ACID properties help the database stay healthy in multi-transactional environments and in case of failure.
● Multiuser and Concurrent Access − DBMS supports multi-user environment and allows them to access
and manipulate data in parallel. Though there are restrictions on transactions when users attempt to handle
the same data item, but users are always unaware of them.
● Multiple views − DBMS offers multiple views for different users. A user who is in the Sales department will
have a different view of database than a person working in the Production department. This feature enables
the users to have a concentrate view of the database according to their requirements.
● Security − Features like multiple views offer security to some extent where users are unable to access data
of other users and departments. DBMS offers methods to impose constraints while entering data into the
database and retrieving the same at a later stage. DBMS offers many different levels of security features,
which enables multiple users to have different views with different features. For example, a user in the Sales
department cannot see the data that belongs to the Purchase department. Additionally, it can also be
managed how much data of the Sales department should be displayed to the user. Since a DBMS is not
saved on the disk as traditional file systems, it is very hard for miscreants to break the code.
Users
A typical DBMS has users with different rights and permissions who use it for different purposes. Some users retrieve
data and some back it up. The users of a DBMS can be broadly categorized as follows −
● Administrators − Administrators maintain the DBMS and are responsible for administrating the database.
They are responsible to look after its usage and by whom it should be used. They create access profiles for
users and apply limitations to maintain isolation and force security. Administrators also look after DBMS
resources like system license, required tools, and other software and hardware related maintenance.
● Designers − Designers are the group of people who actually work on the designing part of the database.
They keep a close watch on what data should be kept and in what format. They identify and design the
whole set of entities, relations, constraints, and views.
● End Users − End users are those who actually reap the benefits of having a DBMS. End users can range
from simple viewers who pay attention to the logs or market rates to sophisticated users such as business
analysts.
1. Data Integrity
Data integrity means data is consistent and accurate in the database. It is essential as there are multiple databases in DBMS. All these databases
contain data which is visible to multiple users. Therefore, it is essential to ensure that data is consistent and correct in all databases for all users.
2. Data Security
Data security is a vital concept in a database. Only users authorized must be allowed to access the database and their identity must be authenticated
using username and password. Unauthorized users shouldn’t be allowed to access the database under any circumstances as it violets the integrity
constraints.
A DBMS provides a better platform for data privacy thus helping companies to offer an improved data security.
1. What is the bonus given to every salesperson in the last two months?
5. Simplicity
DBMS allows us to understand data better with a clear and simple logical view. With dbms, many operations like deletion, insertion or creation of file or
data, are easy to implement.
Additionally, today DBMS is also serving as the backbone of several advanced Technology practices like Data Science, Data Modelling and Machine
Learning. So, if you are someone looking for a career in analytics or automation then dbms is a must have skill for you.
For example, Suppose we design a school database. In this database, the student will be an entity with attributes like address, name, id, age, etc.
The address can be another entity with attributes like city, street name, pin code, etc and there will be a relationship between them.
Component of ER Diagram
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as rectangles.
Consider an organization as an example- manager, product, employee, department etc. can be taken as an entity.
a. Weak Entity
An entity that depends on another entity called a weak entity. The weak entity doesn't contain any key attribute of its own. The weak entity is
represented by a double rectangle.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.
For example, id, age, contact number, name, etc. can be attributes of a student.
a. Key Attribute
The key attribute is used to represent the main characteristics of an entity. It represents a primary key. The key attribute is represented by an
ellipse with the text underlined.
b. Composite Attribute
An attribute that composed of many other attributes is known as a composite attribute. The composite attribute is represented by an ellipse, and
those ellipses are connected with an ellipse.
c. Multivalued Attribute
An attribute can have more than one value. These attributes are known as a multivalued attribute. The double oval is used to represent
multivalued attribute.
For example, a student can have more than one phone number.
d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It can be represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another attribute like Date of birth.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used to represent the relationship.
a. One-to-One Relationship
When only one instance of an entity is associated with the relationship, then it is known as one to one relationship.
For example, A female can marry to one male, and a male can marry to one female.
b. One-to-many relationship
When only one instance of the entity on the left, and more than one instance of an entity on the right associates with the relationship then this is
known as a one-to-many relationship.
For example, Scientist can invent many inventions, but the invention is done by the only specific scientist.
c. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an entity on the right associates with the relationship then it is
known as a many-to-one relationship.
For example, Student enrolls for only one course, but a course can have many students.
d. Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of an entity on the right associates with the relationship then
it is known as a many-to-many relationship.
For example, Employee can assign by many projects and project can have many employees.
ER (Entity Relationship) Diagram in DBMS
o ER model stands for an Entity-Relationship model. It is a high-level data model. This model is used to define the data elements and
relationship for a specified system.
o It develops a conceptual design for the database. It also develops a very simple and easy to design view of data.
o In ER modeling, the database structure is portrayed as a diagram called an entity-relationship diagram.
For example, Suppose we design a school database. In this database, the student will be an entity with attributes like address, name, id, age, etc.
The address can be another entity with attributes like city, street name, pin code, etc and there will be a relationship between them.
Component of ER Diagram
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as rectangles.
Consider an organization as an example- manager, product, employee, department etc. can be taken as an entity.
a. Weak Entity
An entity that depends on another entity called a weak entity. The weak entity doesn't contain any key attribute of its own. The weak entity is
represented by a double rectangle.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.
For example, id, age, contact number, name, etc. can be attributes of a student.
a. Key Attribute
The key attribute is used to represent the main characteristics of an entity. It represents a primary key. The key attribute is represented by an
ellipse with the text underlined.
b. Composite Attribute
An attribute that composed of many other attributes is known as a composite attribute. The composite attribute is represented by an ellipse, and
those ellipses are connected with an ellipse.
c. Multivalued Attribute
An attribute can have more than one value. These attributes are known as a multivalued attribute. The double oval is used to represent
multivalued attribute.
For example, a student can have more than one phone number.
d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It can be represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another attribute like Date of birth.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used to represent the relationship.
a. One-to-One Relationship
When only one instance of an entity is associated with the relationship, then it is known as one to one relationship.
For example, A female can marry to one male, and a male can marry to one female.
b. One-to-many relationship
When only one instance of the entity on the left, and more than one instance of an entity on the right associates with the relationship then this is
known as a one-to-many relationship.
For example, Scientist can invent many inventions, but the invention is done by the only specific scientist.
c. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an entity on the right associates with the relationship then it is
known as a many-to-one relationship.
For example, Student enrolls for only one course, but a course can have many students.
d. Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of an entity on the right associates with the relationship then
it is known as a many-to-many relationship.
For example, Employee can assign by many projects and project can have many employees.
ER (Entity Relationship) Diagram in DBMS
o ER model stands for an Entity-Relationship model. It is a high-level data model. This model is used to define the data elements and
relationship for a specified system.
o It develops a conceptual design for the database. It also develops a very simple and easy to design view of data.
o In ER modeling, the database structure is portrayed as a diagram called an entity-relationship diagram.
For example, Suppose we design a school database. In this database, the student will be an entity with attributes like address, name, id, age, etc.
The address can be another entity with attributes like city, street name, pin code, etc and there will be a relationship between them.
Component of ER Diagram
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as rectangles.
Consider an organization as an example- manager, product, employee, department etc. can be taken as an entity.
a. Weak Entity
An entity that depends on another entity called a weak entity. The weak entity doesn't contain any key attribute of its own. The weak entity is
represented by a double rectangle.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.
For example, id, age, contact number, name, etc. can be attributes of a student.
a. Key Attribute
The key attribute is used to represent the main characteristics of an entity. It represents a primary key. The key attribute is represented by an
ellipse with the text underlined.
b. Composite Attribute
An attribute that composed of many other attributes is known as a composite attribute. The composite attribute is represented by an ellipse, and
those ellipses are connected with an ellipse.
c. Multivalued Attribute
An attribute can have more than one value. These attributes are known as a multivalued attribute. The double oval is used to represent
multivalued attribute.
For example, a student can have more than one phone number.
d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It can be represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another attribute like Date of birth.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used to represent the relationship.
a. One-to-One Relationship
When only one instance of an entity is associated with the relationship, then it is known as one to one relationship.
For example, A female can marry to one male, and a male can marry to one female.
b. One-to-many relationship
When only one instance of the entity on the left, and more than one instance of an entity on the right associates with the relationship then this is
known as a one-to-many relationship.
For example, Scientist can invent many inventions, but the invention is done by the only specific scientist.
c. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an entity on the right associates with the relationship then it is
known as a many-to-one relationship.
For example, Student enrolls for only one course, but a course can have many students.
d. Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of an entity on the right associates with the relationship then
it is known as a many-to-many relationship.
For example, Employee can assign by many projects and project can have many employees.
Difference between Strong and Weak Entity
●
●
●
Prerequisite – ER Model
Strong Entity:
A strong entity is not dependent on any other entity in the schema. A strong entity will always have a primary key. Strong entities are
represented by a single rectangle. The relationship of two strong entities is represented by a single diamond.
Various strong entities, when combined together, create a strong entity set.
Weak Entity:
A weak entity is dependent on a strong entity to ensure its existence. Unlike a strong entity, a weak entity does not have any primary
key. It instead has a partial discriminator key. A weak entity is represented by a double rectangle.
The relation between one strong and one weak entity is represented by a double diamond. This relationship is also known
as identifying relationship.
The relational model means that the logical data structures—the data tables, views, and indexes—are separate
from the physical storage structures. This separation means that database administrators can manage physical
data storage without affecting access to that data as a logical structure.
The RDBMS is the most popular database system among organizations across the world. It provides a dependable method
of storing and retrieving large amounts of data while offering a combination of system performance and ease of
implementation.
RDBMS vs. DBMS
In general, databases store sets of data that can be queried for use in other applications. A database management system
supports the development, administration and use of database platforms.
An RDBMS is a type of database management system (DBMS) that stores data in a row-based table structure which
connects related data elements. An RDBMS includes functions that maintain the security, accuracy, integrity and
consistency of the data. This is different than the file storage used in a DBMS.
Other differences between database management systems and relational database management systems include:
● Number of allowed users. While a DBMS can only accept one user at a time, an RDBMS can operate with multiple
users.
● Hardware and software requirements. A DBMS needs less software and hardware than an RDBMS.
● Amount of data. RDBMSes can handle any amount of data, from small to large, while a DBMS can only manage small
amounts.
● Database structure. In a DBMS, data is kept in a hierarchical form, whereas an RDBMS utilizes a table where the
headers are used as column names and the rows contain the corresponding values.
● ACID implementation. DBMSes do not use the atomicity, consistency, isolation and durability (ACID) model for storing
data. On the other hand, RDBMSes base the structure of their data on the ACID model to ensure consistency.
● Distributed databases. While an RDBMS offers complete support for distributed databases, a DBMS will not provide
support.
● Types of programs managed. While an RDBMS helps manage the relationships between its incorporated tables of
data, a DBMS focuses on maintaining databases that are present within the computer network and system hard disks.
● Support of database normalization. An RDBMS can be normalized, but a DBMS cannot.
The most basic RDBMS functions are related to create, read, update and delete operations -- collectively known as CRUD.
They form the foundation of a well-organized system that promotes consistent treatment of data.
The RDBMS typically provides data dictionaries and metadata collections that are useful in data handling. These
programmatically support well-defined data structures and relationships. Data storage management is a common capability
of the RDBMS, and this has come to be defined by data objects that range from binary large object -- or blob -- strings
to stored procedures. Data objects like this extend the scope of basic relational database operations and can be handled in
a variety of ways in different RDBMSes.
The most common means of data access for the RDBMS is SQL. Its main language components comprise data
manipulation language and data definition language statements. Extensions are available for development efforts that pair
SQL use with common programming languages, such as the Common Business-Oriented Language (COBOL), Java and
.NET.
RDBMSes use complex algorithms that support multiple concurrent user access to the database while maintaining data
integrity. Security management, which enforces policy-based access, is yet another overlay service that the RDBMS
provides for the basic database as it is used in enterprise settings.
RDBMSes support the work of database administrators (DBAs) who must manage and monitor database activity. Utilities
help automate data loading and database backup. RDBMSes manage log files that track system performance based on
selected operational parameters. This enables measurement of database usage, capacity and performance, particularly
query performance. RDBMSes provide graphical interfaces that help DBAs visualize database activity.
While not limited solely to the RDBMS, ACID compliance is an attribute of relational technology that has proved important in
enterprise computing. These capabilities have particularly suited RDBMSes for handling business transactions.
As RDBMSes have matured, they have achieved increasingly higher levels of query optimization, and they have become
key parts of reporting, analytics and data warehousing applications for businesses as well. RDBMSes are intrinsic to
operations of a variety of enterprise applications and are at the center of most master data management systems.
Within the table are rows and columns. The rows are known as records or horizontal entities; they contain the information for
the individual entry. The columns are known as vertical entities and possess information about the specific field.
Before creating these tables, the RDBMS must check the following constraints:
● Primary keys -- this identifies each row in the table. One table can only contain one primary key. The key must be unique
and without null values.
● Foreign keys -- this is used to link two tables. The foreign key is kept in one table and refers to the primary key
associated with another table.
● Not null -- this ensures that every column does not have a null value, such as an empty cell.
● Check -- this confirms that each entry in a column or row satisfies a precise condition and that every column holds unique
data.
● Data integrity -- the integrity of the data must be confirmed before the data is created.
Assuring the integrity of data includes several specific tests, including entity, domain, referential and user-defined integrity.
Entity integrity confirms that the rows are not duplicated in the table. Domain integrity makes sure that data is entered into
the table based on specific conditions, such as file format or range of values. Referential integrity ensures that any row that
is re-linked to a different table cannot be deleted. Finally, user-defined integrity confirms that the table will satisfy all
user-defined conditions.
● Flexibility -- updating data is more efficient since the changes only need to be made in one place.
● Maintenance -- database administrators can easily maintain, control and update data in the database. Backups also
become easier since automation tools included in the RDBMS automate these tasks.
● Data structure -- the table format used in RDBMSes is easy to understand and provides an organized and structural
manner through which entries are matched by firing queries.
On the other hand, relational database management systems do not come without their disadvantages. For example, in
order to implement an RDBMS, special software must be purchased. This introduces an additional cost for execution. Once
the software is obtained, the setup process can be tedious since it requires millions of lines of content to be transferred into
the RDBMS tables. This process may require the additional help of a programmer or a team of data entry specialists.
Special attention must be paid to the data during entry to ensure sensitive information is not placed into the wrong hands.
Some other drawbacks of the RDBMS include the character limit placed on certain fields in the tables and the inability to fully
understand new forms of data -- such as complex numbers, designs and images.
Furthermore, while isolated databases can be created using an RDBMS, the process requires large chunks of information to
be separated from each other. Connecting these large amounts of data to form the isolated database can be very
complicated.
Uses of RDBMS
Relational database management systems are frequently used in disciplines such as manufacturing, human resources and
banking. The system is also useful for airlines that need to store ticket service and passenger documentation information as
well as universities maintaining student databases.
Some examples of specific systems that use RDBMS include IBM, Oracle, MySQL, Microsoft SQLServer and PostgreSQL.
Codd's work was based around a concept of data normalization, which saved file space on storage disk drives at a time
when such machinery could be prohibitively expensive for businesses.
File systems and database management systems preceded what could be called the RDBMS era. Such systems ran
primarily on mainframe computers. While RDBMSes also ran on mainframes -- IBM's DB2 being a pointed example -- much
of their ascendance in the enterprise was in UNIX midrange computer deployments. The RDBMS was a linchpin in the
distributed architecture of client-server computing, which connected pools of stand-alone personal computers to file and
database servers.
Numerous RDBMSes arose along with the use of client-server computing. Among the competitors were Oracle, Ingres,
Informix, Sybase, Unify, Progress and others. Over time, three RDBMSes came to dominate in commercial implementations.
Oracle, IBM's DB2 and Microsoft's SQL Server, which was based on a design originally licensed from Sybase, found
considerable favor throughout the client-server computing era, despite repeated challenges by competing technologies.
As the 20th century drew to an end, lower-cost, open source versions of RDBMSes began to find use, particularly in web
applications.
Eventually, as distributed computing took greater hold, and as cloud architecture became more prominently employed,
RDBMSes met competition in the form of NoSQL systems. Such systems were often specifically designed for massive
distribution and high scalability in the cloud, sometimes forgoing SQL-style full consistency for so-called eventual
consistency of data. But, even in the most diverse and complex cloud systems, the need for some guaranteed data
consistency requires RDBMSes to appear in some way, shape or form. Moreover, versions of RDBMSes have been
significantly restructured for cloud parallelization and replication.
RDBMS terminologies
RDMS Terminologies include Database, Table, Columns, etc. Let us see them one by one −
Database
Database is a collection of tables like <Student>, <Professors>, etc.
Table
A table is a collection of rows and columns , for example,
052 Tom 1
035 David 2
077 John 3
Column
Column is in a table −
Row
Row is also called a tuple in RDBMS.
A relation in a database has rows and columns.
Primary Key
Every table has one Primary key and cannot have null values.
For example, ProjectID is a primary key in Project Table, since it uniquely identifies the project:
ProjectID ProjectName
For example, if a customer can only have one shipping address, then an integrity constraint can be used
to ensure that only one shipping address is entered for each customer. Enforcing integrity constraints in
SQL can help prevent data inconsistencies and errors, making it easier to manage and query the data.
In other cases, they can be used to enforce data integrity, such as ensuring that all values in a column are
unique. Integrity constraints in SQL can be either enforced by the database system or by application
code. Enforcing them at the database level can help ensure that the rules are always followed, even if the
application code is changed. However, enforcing them at the application level can give the developer
more flexibility in how the rules are enforced.
Integrity constraints in DBMS are used to ensure that data is consistent and accurate. There are four
main types of integrity constraints: domain, entity, referential, and key. Here, we'll take a closer look &
explain the types of integrity constraints along with some examples.
1. Domain Constraint
A domain constraint is a restriction on the values that can be stored in a column. For example, if you have
a column for "age," domain integrity constraints in DBMS would ensure that only values between 1 and
120 can be entered into that column. This ensures that only valid data is entered into the database.
An entity integrity constraint is a restriction on null values. Null values are values that are unknown or not
applicable, and they can be problematic because they can lead to inaccurate results. Entity integrity
constraints would ensure that null values are not entered into any required columns. For example, if you
have a column for "first name," an entity integrity constraint in DBMS would ensure that this column
cannot contain any null values.
A referential integrity constraint is a restriction on how foreign keys can be used. A foreign key is a
column in one table that references a primary key in another table. For example, let's say you have a
table of employees and a table of department managers. The "employee ID" column in the employee's
table would be a foreign key that references the "manager ID" column in the manager's table.
Referential integrity constraints in DBMS would ensure that every manager ID in the manager's table has
at least one corresponding employee ID in the employee's table. In other words, it would prevent you from
assigning an employee to a manager who doesn't exist.
4. Key Constraint
Key constraints in DBMS are a restriction on duplicate values. A key is composed of one or more columns
whose values uniquely identify each row in the table. For example, let's say you have a table of products
with columns for "product ID" and "product name." The combination of these two values would be the key
for each product, and a key constraint would ensure that no two products have the same combination of
product ID and product name.
Within databases, a key constraint is a rule that defines how data in a column(s) can be stored in a table.
There are several different types of key constraints in DBMS, each with its own specific purpose. Now,
we'll take a high-level look at the five most common types of key constraints: primary key constraints,
unique key constraints, foreign key constraints, NOT NULL constraints, and check constraints.
1. Primary Key Constraints
A primary key constraint (also known as a "primary key") is a type of key constraint that requires every
value in a given column to be unique. In other words, no two rows in a table can have the same value for
their primary key column(s). A primary key can either be a single column or multiple columns (known as a
"composite" primary key). The null value is not allowed in the primary key column(s).
A unique key constraint is a column or set of columns that ensures that the values stored in the column
are unique. A table can have more than one unique key constraint, unlike the primary key. A unique key
column can contain NULL values. Like primary keys, unique keys can be made up of a single column or
multiple columns.
A foreign key constraint defines a relationship between two tables. A foreign key in one table references a
primary key in another table. Foreign keys prevent invalid data from being inserted into the foreign key
column. Foreign keys can reference a single column or multiple columns.
A NOT NULL constraint is used to ensure that no row can be inserted into the table without a value being
specified for the column(s) with this type of constraint. Thus, every row must have a non-NULL value for
these columns.
5. Check Constraints
A check constraint enforces data integrity by allowing you to specify conditions that must be met for data
to be inserted into a column. For example, you could use a check constraint to ensure that only positive
integer values are inserted into a particular column. Check constraints are usually used in combination
with other constraints (such as NOT NULL constraints) to enforce more complex rules.
There are several different types of key constraints in DBMS that you can use in SQL databases. Each
type of constraint has its own specific use cases and benefits. By understanding when to use each type of
constraint, you can ensure that your database is both reliable and consistent. For in-depth knowledge of
the types of integrity constraints, you can go for the MongoDB Administration certification & expand
your knowledge and develop a stronger outlook.
1. Declarative Ease
One of the advantages of integrity constraints is that they can be declared easily. Integrity constraints are
written in a declarative language, which means that they can be specified without having to write code.
This makes it easy for even non-technical users to understand and specify rules.
2. Centralized Rules
Another advantage of integrity constraints is that they provide a centralized way to specify rules.
Therefore, rules only have to be specified once and then they can be enforced across the entire
database. This is much more efficient than having to specify rules individually for each application or user.
3. Flexibility When Loading Data
Integrity constraints also provide flexibility when loading data into the database. When data is loaded into
the database, the integrity constraints are checked automatically. In other words, if there are any
problems with the data, they can be detected and corrected immediately.
Using integrity constraints can also help to maximize application development productivity. This is
because developers do not have to write code to enforce rules; they can simply specify the rules using an
integrity constraint language. This saves time and effort during development and makes it easier to create
consistent and reliable applications.
Finally, using integrity constraints in DBMS provides immediate feedback to users when they attempt to
violate a rule. For example, if a user tries to insert an invalid value into a database column, the database
will reject the attempted insertion and return an error message to the user instead. This provides a clear
indication to the user that their input is incorrect and needs to be corrected.
Finally, they help to optimize performance by ensuring that only valid data is accessed and processed. By
enforcing integrity constraints, databases can maintain a high level of accuracy and consistency while
also preventing unauthorized access and optimizing performance.
A -> B
Above suggests the following:
Example
The following is an example that would make it easier to understand functional dependency −
We have a <Department> table with two attributes − DeptId and DeptName.
DeptId DeptName
001 Finance
002 Marketing
003 HR
Therefore, the above functional dependency between DeptId and DeptName can be determined as DeptId is functionally dependent
on DeptName −
A ->B
Example
We are considering the same <Department> table with two attributes to understand the concept of trivial dependency.
The following is a trivial functional dependency since DeptId is a subset of DeptId and DeptName
A ->B
Normalization
A large database defined as a single relation may result in data duplication. This repetition of data may result in:
What is Normalization?
The main reason for normalizing the relations is removing these anomalies. Failure to eliminate anomalies leads to data redundancy and can
cause data integrity and other problems as the database grows. Normalization consists of a series of guidelines that helps to guide you in creating
a good database structure.
o Insertion Anomaly: Insertion Anomaly refers to when one cannot insert a new tuple into a relationship due to lack of data.
o Deletion Anomaly: The delete anomaly refers to the situation where the deletion of data results in the unintended loss of some other
important data.
o Updatation Anomaly: The update anomaly is when an update of a single data value requires multiple rows of data to be updated.
Normalization works through a series of stages called Normal forms. The normal forms apply to individual relations. The relation is said to be in
particular normal form if it satisfies constraints.
Normal Description
Form
2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully functional
dependent on the primary key.
3NF A relation will be in 3NF if it is in 2NF and no transition dependency exists.
4NF A relation will be in 4NF if it is in Boyce Codd's normal form and has no multi-valued
dependency.
5NF A relation is in 5NF. If it is in 4NF and does not contain any join dependency, joining
should be lossless.
Advantages of Normalization
Disadvantages of Normalization
o You cannot start building the database before knowing what the user needs.
o The performance degrades when normalizing the relations to higher normal forms, i.e., 4NF, 5NF.
o It is very time-consuming and difficult to normalize relations of a higher degree.
o Careless decomposition may lead to a bad database design, leading to serious problems.
EMPLOYEE table:
14 John 7272826385, UP
9064738238
The decomposition of the EMPLOYEE table into 1NF has been shown below:
14 John 9064738238 UP
Example: Let's assume, a school can store the data of teachers and the subjects they teach. In a school, a teacher can teach more than one
subject.
TEACHER table
25 Chemistry 30
25 Biology 30
47 English 35
83 Math 38
83 Computer 38
In the given table, non-prime attribute TEACHER_AGE is dependent on TEACHER_ID which is a proper subset of a candidate key. That's why it
violates the rule for 2NF.
To convert the given table into 2NF, we decompose it into two tables:
TEACHER_DETAIL table:
TEACHER_ID TEACHER_AGE
25 30
47 35
83 38
TEACHER_SUBJECT table:
TEACHER_ID SUBJECT
25 Chemistry
25 Biology
47 English
83 Math
83 Computer
A relation is in third normal form if it holds atleast one of the following conditions for every non-trivial function dependency X → Y.
1. X is a super key.
2. Y is a prime attribute, i.e., each element of Y is part of some candidate key.
Example:
EMPLOYEE_DETAIL table:
Non-prime attributes: In the given table, all attributes except EMP_ID are non-prime.
Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and EMP_ZIP dependent on EMP_ID. The non-prime attributes (EMP_STATE,
EMP_CITY) transitively dependent on super key(EMP_ID). It violates the rule of third normal form.
That's why we need to move the EMP_CITY and EMP_STATE to the new <EMPLOYEE_ZIP> table, with EMP_ZIP as a Primary key.
EMPLOYEE table:
EMPLOYEE_ZIP table:
201010 UP Noida
02228 US Boston
60007 US Chicago
06389 UK Norwich
462007 MP Bhopal
Example: Let's assume there is a company where employees work in more than one department.
EMPLOYEE table:
1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate key: {EMP-ID, EMP-DEPT}
The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone are keys.
To convert the given table into BCNF, we decompose it into three tables:
EMP_COUNTRY table:
EMP_ID EMP_COUNTRY
264 India
264 India
EMP_DEPT table:
EMP_DEPT_MAPPING table:
EMP_ID EMP_DEPT
D394 283
D394 300
D283 232
D283 549
Functional dependencies:
1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate keys:
Now, this is in BCNF because left side part of both the functional dependencies is a key.
Introduction to SQL
SQL is a standard language for accessing and manipulating databases.
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
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 mann
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.
What are the advantages and disadvantages of SQL
The followings are the advantages and disadvantages of SQL:
Advantages Disadvantages
Standardization Cost
Advantages of SQL
1. Efficient data retrieval – SQL allows for fast and efficient retrieval of specific data from large databases, making
it easier for businesses to find the information they need quickly.
2. Data integrity – SQL helps ensure the accuracy and consistency of data by enforcing constraints and rules that
prevent errors or invalid data from being added to the database.
3. Scalability – SQL is scalable, meaning it can be used to manage databases of any size, from small business
databases to large enterprise databases.
4. Standardization – SQL is a standardized language, which means that it can be used across different database
management systems and platforms.
5. Flexibility – SQL can be used for a variety of tasks, from simple data retrieval to complex data analysis and
management.
Character data These are used to store character strings. Examples include CHAR,
types VARCHAR, and TEXT.
These are used to store date and time values. Examples include
DATE
Date and time data
, TIME, and
types
TIMESTAMP
.
These are used to store binary data, such as images or audio files.
Binary data types
Examples include BLOB and BYTEA.
Data Type Properties
This data type is used to store logical values. The only possible values
Boolean data type
are TRUE and FALSE.
XML data type This data type is used to store XML data.
Binary Datatypes
There are four subtypes of this datatype which are given below:
Data Type Description
bit 0 1
DATETIME A data type is used to store both the data,date, and time in the record.
XML Datatype
XML data type allows storage of XML documents and fragments in a SQL Server database
DataType Description
XML Datatype A Datatype used to store data in the format of XML datatype
Spatial Dataype
A datatype is used for storing planar spatial data, such as points, lines, and polygons, in a database table.
DataType Description
A datatype is used for storing planar spatial data, such as points, lines,
Geometry
and polygons, in a database table.
Array Datatype
SQL Server does not have a built-in array datatype. However, it is possible to simulate arrays using tables or XML data types.
SQL Literals
There are four kinds of literal values supported in SQL. They are : Character string, Bit string, Exact numeric, and
Approximate numeric. These are explained as following below.
1. Character string :
Character strings are written as a sequence of characters enveloped in single quotes. the only quote character is
delineate at intervals a personality string by 2 single quotes. Some example of character strings are :
● ‘My String’
● ‘I love GeeksForGeeks’
● ‘16378’
2. Bit string :
A bit string is written either as a sequence of 0s and 1s enveloped in single quotes and preceded by the letter ‘B’
or as a sequence of positional representation system digits enveloped in single quotes and preceded by the letter
X’ some examples are given below :
● B’10001011′
● B’1′
● B’0′
● X’C 5′
● X’0′
3. Exact numeric :
These literals ar written as a signed or unsigned decimal variety probably with mathematical notation.
Samples of actual numeric literals are given below :
4. Approximate numeric :
Approximate numeric literals are written as actual numeric literals followed by the letter ‘E’, followed by
a signed or unsigned number. Some example are :
● 6E6
● 66.6E6
● +66E-6
● 0.66E
● -6.66E-8
If you haven’t already done so, create a database where the table will be stored. For example, you may use the following query to
create a database called the test_database:
For instance, let’s create a table called ‘products‘ which contains 2 columns:
● product_name
● price
The table should store the following data:
product_name price
Laptop 1200
Tablet 200
Monitor 350
Printer 150
Where the data type for the ‘product_name‘ column would be nvarchar(50), while the data type for the ‘price‘ column would
be int (for integers).
You can then create the table using the following CREATE TABLE query under your database:
product_name nvarchar(50),
price int
Let’s now add the following values into the ‘products’ table:
product_name price
Laptop 1200
Tablet 200
Monitor 350
Printer 150
You can insert values into the table using an INSERT INTO query:
VALUES
('Desktop Computer',800),
('Laptop',1200),
('Tablet',200),
('Monitor',350),
('Printer',150)
Step 4: Verify that the values were inserted into the table
Finally, run the following SELECT query to verify that the values were inserted into the table:
product_name price
Laptop 1200
Tablet 200
Monitor 350
Printer 150
Create a Table in SQL Server with Primary Key and Identity Column
A Primary Key uniquely identifies each record (i.e., row) in your table, while an Identity Column ensures that an auto-increment is
applied to your column whenever a new record is inserted into the table.
Let’s say that you want to create a table with a Primary Key and Identity Column.
For example, suppose that you want to recreate the ‘products‘ table with the following 3 columns:
● product_id
● product_name
● price
Where the product_id column will be selected as the Primary Key as well as the Identity Column.
This is how the new ‘products‘ table should look like:
product_id product_name price
2 Laptop 1200
3 Tablet 200
4 Monitor 350
5 Printer 150
product_name nvarchar(50),
price int
You can then add records to the table by running this INSERT INTO query:
VALUES
('Desktop Computer',800),
('Laptop',1200),
('Tablet',200),
('Monitor',350),
('Printer',150)
5 new records will be inserted into the table (notice that it wasn’t necessary to populate the product_id column using the insert query.
This was taken care by setting the product_id column as the Identity Column).
2 Laptop 1200
3 Tablet 200
4 Monitor 350
5 Printer 150
In the SQL server, the SQL DELETE & UPDATE keywords are more frequently used after the SQL SELECT keyword.
?
UPDATE Table_Name
[WHERE CONDITION];
● [UPDATE Table_Name] – This command is used to tell the database to modify the records from specified
Table_Name.
● [SET ‘Column_Name’ = ‘New_value’] – ‘Column_Name’ is the name the column for which you have to modify the
value & ‘New_value’ are the actual value which you have to set. While setting up the new values you have to enter
the new values based on the column’s data type, which means if the column value is Full_Name with data type
varchar then you have to specify the values in the single quotes. Similarly, for the date data type, you have to enter
date values single quotes. Numeric values you have to specify the values without quotes.
● [WHERE CONDITION] – This Clause used to filter out the result data set based on “condition”. You can specify
any condition using the WHERE clause.
Let’s go ahead & learn to update queries with practical examples. In the Employee table, each record has a Phone & one
Employee wants to change the phone number in the employee record & the second employee wants to update the Full
name. So let’s see how to update the Phone number using the UPDATE query.
?
SELECT * FROM Employee WHERE Employee_Id IN
(1,2);
Full_Nam Gende
Employee_Id Date_Of_Birth Phone
e r
1 Tanya 912345678
Female 1982-09-30
Smith 9
2 Janet 987654321
Female 1980-07-10
Tampi 0
3 911223344
Nilsen Phil Male NULL
5
4 Nilsen 998877665
Male 1983-09-17
Jones 5
5 Pettersen 994455229
Male 1980-07-12
Willams 9
6 Angels 995556661
Male 1981-02-10
David 1
The Employee “Tanya Smith” wants to change phone number from “9123456789” to “9198657777” & “Janet Tampi” want to
update the Full name to “Janet Tampi – Simson” & Date of birth to “1980-07-10”, so you can use the following update
queries to modify the records.
?
UPDATE Employee
WHERE Employee_Id&amp;amp;nbsp; = 1;
?
UPDATE Employee
Note: If you want to update the multiple values in the same condition then you can use the comma operator in the “SET” &
pass the multiple values.
Executing the above script the values in the Employee table are updated based on the values specified in the update query.
?
SELECT * FROM Employee WHERE Employee_Id IN
(1,2);
Full_Nam Gende
Employee_Id Date_Of_Birth Phone
e r
1 Tanya 919865777
Female 1982-09-30
Smith 7
Janet
2 987654321
Tampi – Female 1980-07-10
0
Simson
3 911223344
Nilsen Phil Male NULL
5
4 Nilsen 998877665
Male 1983-09-17
Jones 5
5 Pettersen 994455229
Male 1980-07-12
Willams 9
6 Angels 995556661
Male 1981-02-10
David 1
As it name suggests that the DELETE keyword is used to delete the record(s) from the database when they are no longer be
used. Using the DELETE keyword you can delete single or multiple records from the database. So this command is used
more powerfully with WHERE keyword while removing the unnecessary records from the database.
Upon executing this command the deleted data cannot be recovered, so prior to executing this command you should make
sure with where condition in the query is correct. To be on the safer side, take the backups of the database or tables from
where you are executing the delete query, so it will help you to compare the records after executing the query.
?
DELETE from Table_Name
[WHERE CONDITION];
In the above case, we have specified WHERE condition, so the records will be deleted from the table based on the criteria
you specified.
You can also use the following command to delete all the data from the table, so the only difference is don’t specify
the WHERE condition:
?
DELETE from Table_Name;
● [DELETE from Table_Name] – This command is used to tell the database to delete the records from specified
Table_Name.
● [WHERE CONDITION] – This Clause used to filter out the result data set based on “condition”. You can specify
any condition using the WHERE clause.
Let’s see upon executing following query on Employee table resulting following list:
?
SELECT&amp;amp;nbsp;*&amp;amp;nbsp;FROM&amp;amp;nbsp;Employee
Full_Nam Gende
Employee_Id Date_Of_Birth Phone
e r
1 Tanya 912345678
Female 1982-09-30
Smith 9
2 Janet 987654321
Female 1980-07-10
Tampi 0
3 911223344
Nilsen Phil Male NULL
5
4 Nilsen 998877665
Male 1983-09-17
Jones 5
5 Pettersen 994455229
Male 1980-07-12
Willams 9
6 Angels 995556661
Male 1981-02-10
David 1
Let take an example of Employee where the “Nilsen Jones” employee left the company and they want to remove the
employee record from the database. Its Employee_Id is 4, so we can write down the delete query on Employee table where
pass the Employee_Id in the WHERE condition to delete the specific employee record.
?
DELETE FROM Employee WHERE Employee_Id = 4;
Once we execute the above script then the “Nilsen Jones” record will be deleted from Employee list and Employee table will
look like as follows:
Gende
Employee_Id Full_Name Date_Of_Birth Phone
r
1 912345678
Tanya Smith Female 1982-09-30
9
2 987654321
Janet Tampi Female 1980-07-10
0
3 911223344
Nilsen Phil Male NULL
5
5 994455229
Pettersen Willams Male 1980-07-12
9
6 995556661
Angels David Male 1981-02-10
1
If we check the employee id record 4, then this record is deleted from the Employee table & not returned in the result set.
Also, keep in mind the column can be deleted using delete command, the entire row will be deleted.
If you want to delete multiple records from the table then this can be accomplished using IN wildcard. Only you have to
provide the list of record which you want to delete in WHERE clause.
?
DELETE FROM Employee WHERE Employee_Id IN (3,5);
Once we execute the above query then the employee IDs 3 & 5 entries from the employee table will be removed.
SQL Commands
o SQL commands are instructions. It is used to communicate with the database. It is also used to perform specific tasks, functions, and queries of
data.
o SQL can perform various tasks like create a table, add data to tables, drop the table, modify the table, set permission for users.
There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.
o CREATE
o ALTER
o DROP
o TRUNCATE
Syntax:
Syntax
Syntax:
Syntax:
o INSERT
o UPDATE
o DELETE
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table.
Syntax:
Syntax:
1. UPDATE students
2. SET User_Name = 'Sonoo'
3. WHERE Student_Id = '3'
c. DELETE: It is used to remove one or more row from a table.
Syntax:
1. DELETE FROM table_name [WHERE condition];
For example:
o Grant
o Revoke
Example
Example
These operations are automatically committed in the database that's why they cannot be used while creating tables or dropping them.
o COMMIT
o ROLLBACK
o SAVEPOINT
a. Commit: Commit command is used to save all the transactions to the database.
Syntax:
1. COMMIT;
Example:
Syntax:
1. ROLLBACK;
Example:
Syntax:
1. SAVEPOINT SAVEPOINT_NAME;
o SELECT
a. SELECT: This is the same as the projection operation of relational algebra. It is used to select the attribute based on the condition described by WHERE
clause.
Syntax:
1. SELECT expressions
2. FROM TABLES
3. WHERE conditions;
For example:
1. SELECT emp_name
2. FROM employee
3. WHERE age > 20;
SQL Operator
There are various types of SQL operator:
Let's assume 'variable a' and 'variable b'. Here, 'a' contains 20 and 'b' contains 10.
- It is used to subtract the right-hand operand from the left-hand operand. a-b will give
10
/ It is used to divide the left-hand operand by the right-hand operand. a/b will give 2
% It is used to divide the left-hand operand by the right-hand operand and a%b will give
returns reminder. 0
SQL Comparison Operators:
Let's assume 'variable a' and 'variable b'. Here, 'a' contains 20 and 'b' contains 10.
= It checks if two operands values are equal or not, if the values are queal (a=b) is not
then condition becomes true. true
!= It checks if two operands values are equal or not, if values are not equal, (a!=b) is true
then condition becomes true.
<> It checks if two operands values are equal or not, if values are not equal (a<>b) is true
then condition becomes true.
> It checks if the left operand value is greater than right operand value, if yes (a>b) is not
then condition becomes true. true
< It checks if the left operand value is less than right operand value, if yes (a<b) is true
then condition becomes true.
>= It checks if the left operand value is greater than or equal to the right (a>=b) is not
operand value, if yes then condition becomes true. true
<= It checks if the left operand value is less than or equal to the right operand (a<=b) is true
value, if yes then condition becomes true.
!< It checks if the left operand value is not less than the right operand value, if (a!=b) is not
yes then condition becomes true. true
!> It checks if the left operand value is not greater than the right operand (a!>b) is true
value, if yes then condition becomes true.
Operator Description
BETWEEN It is used to search for values that are within a set of values.
Operator Description
INTERVAL Return the index of the argument that is less than the first argument
! Negate values
^ Bitwise XOR
* Multiplication operator
/ Division operator
DIV Integer Division (discard the fractional part of division)
%, MOD Modulo operator
– Minus operator
+ Addition operator
| Bitwise OR
= Comparison operator
<=> NULL-safe equal to operator
>=, > Greater than/Greater than or equal to
<=, < Less than/Less than or equal to
<>, != Not Equal to operator
IS Test a value against a boolean value
Operator Description
BETWEEN
Check whether a value is within a range of values
CASE WHEN
Case operator
THEN ELSE
OR, || Logical OR
1 Payal 12
2 Utkarsh 9
3 Reeta 19
4 Sunny 15
5 Shanu 5
6 Punit 7
From the above table we want the result of those students having marks greater than 10 and whose name starts with either ‘p’ or ‘s’. So, it’s
query can be written as-
mysql>select *
from student
where marks>10 and name like 'p%'
or name like 's%';
Result:
It will produce the desired result:
id name marks
1 Payal 12
4 Sunny 15
id name marks
6 Punit 7
This result set is not as expected from the query. As it is giving the result of a student ‘Punit’ having marks less than 10 which is not required.
Due to higher precedence of operator AND as compare to OR, the above query give result of all those students having marks greater than
10 and name starting with ‘s’, in addition to those the result of those student having name starting with ‘p’ is also given in output. So, here
come role of parentheses. The above-stated query can be written as,
mysql>select *
from student
where marks>10 and (name like 'p%'
or name like 's%');
Result:
It will produce the desired result:
id name marks
1 Payal 12
4 Sunny 15
Hence, this precedence of the operator can be overridden by making use of parenthesis.
Important Rule:
o A subquery can be placed in a number of SQL clauses like WHERE clause, FROM clause, HAVING clause.
o You can use Subquery with SELECT, UPDATE, INSERT, DELETE statements along with the operators like =, <, >, >=, <=, IN, BETWEEN, etc.
o A subquery is a query within another query. The outer query is known as the main query, and the inner query is known as a subquery.
o Subqueries are on the right side of the comparison operator.
o A subquery is enclosed in parentheses.
o In the Subquery, ORDER BY command cannot be used. But GROUP BY command can be used to perform the same function as ORDER BY
command.
SQL subqueries are most frequently used with the Select statement.
Syntax
1. SELECT column_name
2. FROM table_name
3. WHERE column_name expression operator
4. ( SELECT column_name from table_name WHERE ... );
Example
1 John 20 US 2000.00
4 Alina 29 UK 6500.00
1. SELECT *
2. FROM EMPLOYEE
3. WHERE ID IN (SELECT ID
4. FROM EMPLOYEE
5. WHERE SALARY > 4500);
This would produce the following result:
4 Alina 29 UK 6500.00
o SQL subquery can also be used with the Insert statement. In the insert statement, data returned from the subquery is used to insert into another
table.
o In the subquery, the selected data can be modified with any of the character, date functions.
Syntax:
Now use the following syntax to copy the complete EMPLOYEE table into the EMPLOYEE_BKP table.
The subquery of SQL can be used in conjunction with the Update statement. When a subquery is used with the Update statement, then either single or
multiple columns in a table can be updated.
Syntax
1. UPDATE table
2. SET column_name = new_value
3. WHERE VALUE OPERATOR
4. (SELECT COLUMN_NAME
5. FROM TABLE_NAME
6. WHERE condition);
Example
Let's assume we have an EMPLOYEE_BKP table available which is backup of EMPLOYEE table. The given example updates the SALARY by .25 times in the
EMPLOYEE table for all employee whose AGE is greater than or equal to 29.
1. UPDATE EMPLOYEE
2. SET SALARY = SALARY * 0.25
3. WHERE AGE IN (SELECT AGE FROM CUSTOMERS_BKP
4. WHERE AGE >= 29);
This would impact three rows, and finally, the EMPLOYEE table would have the following records.
1 John 20 US 2000.00
4 Alina 29 UK 1625.00
The subquery of SQL can be used in conjunction with the Delete statement just like any other statements mentioned above.
Syntax
Let's assume we have an EMPLOYEE_BKP table available which is backup of EMPLOYEE table. The given example deletes the records from the EMPLOYEE
table for all EMPLOYEE whose AGE is greater than or equal to 29.
1 John 20 US 2000.00
2 Stephan 26 Dubai 1500.00
Built-In functions
Built-In functions are used in SQL SELECT expressions to calculate values and manipulate data. These functions can
be used anywhere expressions are allowed. Common uses of functions include changing a name to all upper case.
What are Built-In Functions?
In SQL a built-in function is a piece for programming that takes zero or more inputs and returns a value. An example of a built-in function is ABS(),
which when given a value calculates the absolute (non-negative) value of the number.
Some functions, such as ABS() are used to perform calculations, others such as GETDATE() are used to obtain a system value, such as the current
data, or others, like LEFT(), are used to manipulate textual data.
FROM production.Product
In this query we first calculate the difference between 500 and a product’s reorder point. The ABS function is then used to return the result as a
positive number.
There are several things to note regarding functions.
1. The inputs to a function are called parameters. Not all function has parameters, and some functions have more than one.
2. Parameters are enclosed in parenthesis.
3. We use functions in the SELECT clause as well as the WHERE filter condition. A function can be used anywhere in a SELECT
statement that you can use an expression.
4. Functions are reserved words. I would avoid using them as column or table names. If you do, then expect to qualify your names with
brackets [].
ROUND ( m [, n ] ) m = value, n = number of decimal places, default 0 m rounded to the nth decimal place
TRUNC ( m [, n ] ) m = value, n = number of decimal places, default 0 m truncated to the nth decimal place
Here are some examples of the use of some of these numeric functions:
select round (83.28749, 2) from dual;
CONCAT ( s1, s2 ) s1 and s2 are character strings Concatenation of s1 and s2. Equivalent to s1 || s2
s1 and s2 are character strings and n is Returns s1 right justified and padded left with n
LPAD ( s1, n [, s2] )
an integer value characters from s2; s2 defaults to space.
s1 and s2 are character strings and n is Returns s1 left justified and padded right with n
RPAD ( s1, n [, s2] )
an integer value characters from s2; s2 defaults to space.
s is a character string and set is a set of Returns s with characters removed up to the first
LTRIM ( s [, set ] )
characters character not in set; defaults to space
s is a character string and set is a set of Returns s with final characters removed after the last
RTRIM ( s [, set ] )
characters character not in set; defaults to space
REPLACE ( s,
s = character string, search_s = target Returns s with every occurrence of search_s in s
search_s [,
string, replace_s = replacement string replaced by replace_s; default removes search_s
replace_s ] )
SUBSTR ( s, m [, n ] s = character string, m = beginning Returns a substring from s, beginning in position m and
) position, n = number of characters n characters long; default returns to end of s.
select initcap ("now is the time for all good men to come to the aid of the
party") as "SLOGAN" from dual;
select substr ('Alan Turing', 1, 4) as "FIRST" from dual;
Group Functions
Function Input Argument Value Returned
e1 and e2 are column Correlation coefficient between the two columns after
CORR ( e1, e2 )
names eliminating nulls
MEDIAN ( col ) col = column name Middle value in the sorted column, interpolating if necessary
STDDEV ( [ DISTINCT |
col = column name Standard deviation of the column ignoring NULL values
ALL ] col )
VARIANCE ( [ DISTINCT |
col = column name Variance of the column ignoring NULL values
ALL ] col )
MONTHS_BETWEEN ( d,
d and e are dates Number of months by which e precedes d
e)
d = date, a = time zone (char), b The date and time in time zone b when date d is for
NEW_TIME ( d, a, b )
= time zone (char) time zone a
NEXT_DAY ( d, day ) d = date, day = day of the week Date of the first day of the week after d
LEAST ( d1, d2, ..., dn ) d1 ... dn = list of dates Earliest of the given dates
Date Formats
Format
Description Range of Values
Code
HH 12 or Hour displayed in 12 or 24
1 - 12 or 1 - 24
HH 24 hour format
MI Minutes of the hour 0 - 59
AM or PM Meridian indicator AM or PM
● Count()
● Sum()
● Avg()
● Min()
● Max()
COUNT() Function
The COUNT() function returns the number of rows in a database table.
Syntax:
COUNT(*)
or
Example:
We will use the ‘products’ table from the sample database for our demonstration.
The following SQL statement fetches the number of products in the table.
The below-given command will display those product ids where the unit price is greater than 4.
The SQL command given below will list the number of customers in each city.
SUM() Function
SUM()
or
Example:
The following SQL statement finds the sum of the "unit price" fields in the "products" table:
Let’s look at how we can use GROUP BY and HAVING functions with the SUM function.
The SQL command below will list the number of customers in each city, having a sum of points greater
than 3000.
Syntax:
AVG()
or
AVG( [ALL|DISTINCT] expression )
Example:
MIN() Function
The MIN() aggregate function returns the lowest value (minimum) in a set of non-NULL values.
Syntax:
MIN()
or
The above code will give us the minimum quantity in stock in the products table.
MAX() Function
The MAX() aggregate function returns the highest value (maximum) in a set of non-NULL values.
Syntax:
AVG()
or
AVG( [ALL|DISTINCT] expression )
Example:
The code depicted below will give us the maximum quantity in stock in the products table.
An SQL join operation matches rows from two or more related tables according to a condition and creates
a single data set with columns selected from across the multiple tables. Typically, the condition matches
keys from the two tables by an equality predicate. Join operators perform the same function in a data flow,
and support inner joins, outer joins, and cross-joins of multiple input data sets.
With a join operator, you can perform the following types of joins:
Inner
Rows that are not common to all of the tables being joined are dropped from the result table.
Left outer
Returns all the rows that would be returned by an inner join, plus all the rows from the left (or
first-listed) table that do not match any row from the right table.
Right outer
Returns all the inner-join rows, plus all the rows from the right (or second-listed) table that do not
match any row from the left table.
Full outer
Cross
Produces the Cartesian product of all the rows in both tables. (This type of join occurs when you
do not specify a condition.)
● HTML defines the frontend structure and the different DOM elements
● Cascading Style Sheets (CSS) defines the style of a web application, including layout, fonts, colors, and
visual style
● JavaScript adds a layer of dynamic functionality by manipulating the DOM
JavaScript can trigger changes on a page and display new information. This means the frontend can
handle fundamental user interactions (or requests), like displaying a calendar or checking if your user has
entered a valid email address. The frontend passes on more complex requests to the backend.
Frontend developers aim to develop a positive user experience, optimize the application for accessibility and performance, and create responsive designs. Their main
development goals are to ensure the frontend is easy to interact with, well designed, and fully responsive on different platforms and devices.
Backend developers build and then maintain the server-side operations of an application. Their main development goals are to create reliable architecture that performs
application functions accurately and efficiently. They aim to meet user requirements while fulfilling all security and cost considerations.
Technologies
Frontend development touches upon the user-facing side of a website. These technologies include computer languages like JavaScript, CSS, and HTML. Frontend software
development also uses frontend frameworks to speed up production efficiency.
Backend development uses programming languages like Ruby, Java, and Python to write server-side logic. Backend developers also use databases, storage technologies,
and API technologies so applications and systems communicate with each other.