DBMS Final
DBMS Final
Data organization: DBMS allow users to organize large amounts of data in a structured
and systematic way. Data is organized into tables, fields, and records, making it easy to manage,
store, and retrieve information.
Data scalability: DBMS are designed to handle large amounts of data and are scalable to
meet the growing needs of organizations. As organizations grow, DBMS can scale up to handle
increasing amounts of data and user traffic.
o Banking
Database the executive’s framework is utilized to store the exchange data of the client
in the information base
.
o Education Sector
Presently, assessments are led online by numerous schools and colleges. They deal with
all assessment information through the data set administration framework (DBMS). In
spite of that understudy’s enlistments subtleties, grades, courses, expense, participation,
results, and so forth all the data is put away in the information base.
o Data integration: Due to the Database Management System we have access to well-
managed and synchronized forms of data thus it makes data handling very easy and
gives an integrated view of how a particular organization is working and also helps to
keep track of how one segment of the company affects another segment.
o Data abstraction: The major purpose of a database system is to provide users with
an abstract view of the data. Since many complex algorithms are used by the developers
to increase the efficiency of databases that are being hidden by the users through various
data abstraction levels to allow users to easily interact with the system.
o Data consistency and accuracy: DBMS ensures that data is consistent and accurate
by enforcing data integrity constraints and preventing data duplication. This helps to
eliminate data discrepancies and errors that can occur when data is stored and managed
manually.
o Software
Software is a set of programs used to manage and control the database and includes the
database software, operating system, network software used to share the data with other
users, and the applications used to access the data.
o Data
Data are raw facts and information that need to be organized and processed to make it
more meaningful. Database dictionaries are used to centralize, document, control, and
coordinate the use of data within an organization. A database is a repository of
information about a database (also called metadata).
o Procedures
My SQL
o MySQL is a relational database management system
o MySQL is open-source
o MySQL is free
o MySQL is ideal for both small and large applications
o MySQL is very fast, reliable, scalable, and easy to use
o MySQL is cross-platform
o MySQL is compliant with the ANSI SQL standard
o MySQL was first released in 1995
o MySQL is developed, distributed, and supported by Oracle Corporation
o MySQL is named after co-founder Monty Widenius's daughter: My
Features of My SQL
The following are the most important features of MySQL:
MySQL is a relational database management system. This database language is based on the
SQL queries to access and manage the records of the table.
o Easy to use
o It is secure
o Client/ Server Architecture
o Free to download
Advantages of My SQL
Here are some of the main advantages of MySQL:
o Data Security: MySQL is globally renowned for being the most secure and reliable
database management system used in popular web applications, including
WordPress, Drupal, Joomla, Facebook, and Twitter.
o High Performance: MySQL features a different storage-engine framework that
facilitates system administrators to configure the MySQL database server for
flawless performance.
o Cost-Effective: The database is open-source and free.
Disadvantages of My SQL
Here are some of the key disadvantages of MySQL:
Oracle Database
Oracle database is a relational database management system (RDBMS) from Oracle
Corporation. This article will explain a complete overview of the Oracle database, features,
history, and editions. Before discussing the oracle, we will first need to know about the
database.
o Security: Oracle has a mechanism for controlling and accessing the database to
prevent unauthorized access. It provides high security because of the Oracle Advanced
Security features. It offers two solutions to protect databases that are TDE (Transparent
Data Encryption) and Data Redaction. TDE supports data encryption both at the source
and after export. Redaction is performed at the application level. Oracle has some other
security features like Oracle Database Vault that regulates user privileges and Oracle
Label Security.
o Scalability: It provides features like RAC (Real Application Cluster) and Portability,
which makes an Oracle database scalable based on usage. In a clustered environment,
it includes capabilities such as rolling instance migrations, performing upgrades,
maintaining application continuity, quality of service management, etc.
o Performance: Oracle has procedures and principles that help us to get high levels of
database performance. We can increase query execution time and operations with the
use of performance optimization techniques in its database. This technique helps to
retrieve and alter data faster.
o Portability: The Oracle database can be ported on all different platforms than any of
its competitors. We can use this database on around 20 networking protocols as well as
over 100 hardware platforms. This database makes it simple to write an Oracle
application by making changes to the OS and hardware in a secure manner.
o Backup and Recovery: It is always better to take a proper backup of your entire
oracle online backup and recovery. The Oracle database makes it easy to accomplish
recovery quickly by using the. RMAN (Recovery Manager) functionality. It can recover
or restore database files during downtime or outages. It can be used for online backups,
archived backups, and continuous archiving. We can also use SQL* PLUS for recovery,
which is known as user-managed recovery.
o PL/SQL: One of the greatest benefits of using the Oracle database is to support
PL/SQL extension for procedural programming.
o Flashback Technology: This advantage comes with the recent Oracle version. It
allows us to recover those data that are incorrectly deleted or lost by human errors like
accidental deletion of valuable data, deleting the wrong data, or dropping the table.
o Complexity: Oracle is not recommended to use when the users are not technically
savvy and have limited technical skills required to deal with the Oracle Database. It is
also not advised to use if the company is looking for a database with limited
functionality and easy to use.
o Cost: The price of Oracle products is very high in comparison to other databases.
Therefore users are more likely to choose other less expensive options such as MS SQL
Server, MySQL, etc.
o Difficult to manage: Oracle databases are often much more complex and difficult
in terms of the management of certain activities.
Mongo db
MongoDB is a powerful and flexible solution for handling modern data needs. As a leading
NoSQL database, MongoDB offers a dynamic schema design, enabling developers to store and
manage data in a way that aligns seamlessly with contemporary application requirements.
Features of MongoDB
• Schema-less Database: It is the great feature provided by the MongoDB. A
Schema-less database means one collection can hold different types of documents in it.
Or in other words, in the MongoDB database, a single collection can hold multiple
documents and these documents may consist of the different numbers of fields, content,
and size. It is not necessary that the one document is similar to another document like
in the relational databases. Due to this cool feature, MongoDB provides great flexibility
to databases.
• Document Oriented: In MongoDB, all the data stored in the documents instead of
tables like in RDBMS. In these documents, the data is stored in fields(key-value pair)
instead of rows and columns which make the data much more flexible in comparison
to RDBMS. And each document contains its unique object id.
• Replication: MongoDB provides high availability and redundancy with the help of
replication, it creates multiple copies of the data and sends these copies to a different
server so that if one server fails, then the data is retrieved from another server.
• Aggregation: It allows to perform operations on the grouped data and get a single
result or computed result. It is similar to the SQL GROUPBY clause. It provides three
different aggregations i.e, aggregation pipeline, map-reduce function, and single-
purpose aggregation methods
• High Performance: The performance of MongoDB is very high and data
persistence as compared to another database due to its features like scalability,
indexing, replication, etc.
Advantages of MongoDB
• It is a schema-less NoSQL database. You need not to design the schema of the database
when you are working with MongoDB.
Disadvantages of MongoDB
• You are not allowed to store more than 16MB data in the documents.
• The nesting of data in BSON is also limited you are not allowed to nest data more than
100 levels.
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
Types of SQL
DDL or Data Definition Language actually consists of the SQL commands that can be used to
define the database schema. It simply deals with descriptions of the database schema and is
used to create and modify the structure of database objects in the database.
DDL is a set of SQL commands used to create, modify, and delete database structures but not
data. These commands are normally not used by a general user, who should be accessing the
database via an application.
COMMENT 'comment_text' ON
COMMENT Add comments to the data dictionary
TABLE table_name;
This command allows getting the data out of the database to perform operations with it. When
a SELECT is fired against a table or tables the result is compiled into a further temporary table,
which is displayed or perhaps received by the program i.e. a front-end.
DQL Command
The SQL commands that deal with the manipulation of data present in the database belong to
DML or Data Manipulation Language and this includes most of the SQL statements.
It is the component of the SQL statement that controls access to data and to the database.
Basically, DCL statements are grouped with DML statements.
DCL includes commands such as GRANT and REVOKE which mainly deal with the rights,
permissions, and other controls of the database system.
Transactions group a set of tasks into a single execution unit. Each transaction begins with a
specific task and ends when all the tasks in the group are successfully completed. If any of the
tasks fail, the transaction fails.
Therefore, a transaction has only two results: success or failure. You can explore more about
transactions here. Hence, the following TCL commands are used to control the execution of a
transaction:
+ Addition
- Subtract
* Multiply
/ Divide
% Modulo
Operator Description
| Bitwise OR
^ Bitwise exclusive OR
MySQL Comparison Operators
= Equal to
Operator Description
+= Add equals
-= Subtract equals
*= Multiply equals
/= Divide equals
%= Modulo equals
Operators in SQL
Operators in SQL are symbols that help us to perform specific mathematical and logical
computations on operands. An operator can either be unary or binary.
The unary operator operates on one operand, and the binary operator operates on two
operands.
Operator Description
This operator works with the ‘ALL’ keyword and it calculates division
/
operations.
Operator Description
= Equal to.
Operator Description
| Bitwise OR operator
Operator Description
Operators Description
1. String Functions
• UPPER (): Converts a string to uppercase.
SELECT UPPER (name) AS uppercase_name
FROM employees;
2. Numeric Functions
• ROUND(): Rounds a number to a specified number of decimal places.
SELECT ROUND(salary, 2) AS rounded_salary
FROM employees;
3. Date Functions
• CURRENT_DATE: Returns the current date.
SELECT CURRENT_DATE AS today
FROM dual;
• ADD_MONTHS(): Adds a specified number of months to a date.
SELECT ADD_MONTHS(hiringdate, 6) AS new_hire_date
FROM employees;
• EXTRACT(): Retrieves sub-parts from a date (like year, month, day).
SELECT EXTRACT(YEAR FROM hire_date) AS hire_year
FROM employees;
4. Conversion Functions
• TO_CHAR(): Converts a number or date to a string.
SELECT TO_CHAR(hiringdate, 'YYYY-MM-DD') AS formatted_hire_date
FROM employees;
• TO_NUMBER(): Converts a string to a number.
SELECT TO_NUMBER(salary_string) AS salary
FROM employee_salaries;
• TO_DATE(): Converts a string to a date.
SELECT TO_DATE('2024-01-01', 'YYYY-MM-DD') AS formatted_date
FROM dual;
5. Miscellaneous Functions
• NVL(): Replaces null with a specified value.
SELECT NVL(phone_number, 'N/A') AS contact_number
FROM employees;
• COALESCE(): Returns the first non-null value in a list.
SELECT COALESCE(middle_name, 'No Middle Name') AS full_name
FROM employees;
3. AVG()
Calculates the average value of a numeric column.
SELECT departmentid, AVG(salary) AS average_salary
FROM employees
GROUP BY departmentid;
4. MIN()
Returns the minimum value of a column.
SELECT departmentid, MIN(salary) AS lowest_salary
FROM employees
GROUP BY departmentid;
5. MAX()
Returns the maximum value of a column.
SELECT departmentid, MAX(salary) AS highest_salary
FROM employees
GROUP BY departmentid;
7. HAVING
Used to filter groups based on the result of aggregate functions.
SELECT departmentid, COUNT(*) AS employee_count
FROM employees
GROUP BY departmentid
HAVING COUNT(*) > 10;
8. ROLLUP
Creates subtotals and grand totals.
SELECT departmentid, COUNT(*) AS employee_count
FROM employees
GROUP BY ROLLUP(departmentid);
Practical 6
Aim: SQL QUERY EXAMPLES
1. Selecting Data
Basic SELECT Statement
SELECT name
FROM employees;
2. Filtering Data
Using WHERE Clause
SELECT name
FROM employees
WHERE departmentid = 3;
3. Sorting Data
Using ORDER BY
SELECT name, salary
FROM employees
ORDER BY salary DESC;
4. Grouping Data
Using GROUP BY
SELECT departmentid, COUNT(*) AS employee_count
FROM employees
GROUP BY departmentid;
5. Filtering Groups
Using HAVING
SELECT departmentid, AVG(salary) AS average_salary
FROM employees
GROUP BY departmentid
HAVING AVG(salary) > 50000;
6. Joining Tables
INNER JOIN Example
SELECT e.first_name, e.last_name, d.department_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.department_id;
7. Inserting Data
INSERT Statement
INSERT INTO employees (empid,name, department, salary,hiringdate,departmentid)
VALUES (5,'John','engineering', 60000,2020-04-12,5);
8. Updating Data
UPDATE Statement
UPDATE employees
SET salary = salary * 1.10
WHERE departmentid = 2;
9. Deleting Data
DELETE Statement
DELETE FROM employees
WHERE empid = 5;
1. INNER JOIN
Returns rows when there is a match in both tables.
SELECT e. name, d.department
FROM employees
INNER JOIN department d ON e.departmentid = d.departmentid;
6. SELF JOIN
A self join is a join of a table with itself. It is useful for comparing rows within the same
table.
SELECT a.first_name AS Employee, b.first_name AS Manager
FROM employees a
INNER JOIN employees b ON a.manager_id = b.employee_id;
7. NATURAL JOIN
Automatically joins tables based on columns with the same names in both tables. This is less
commonly used because it can lead to unexpected results if there are many matching
columns.
SELECT *
FROM employees
NATURAL JOIN department;
Summary
SQL joins are essential for querying data across multiple tables. By understanding the
different types of joins, you can effectively retrieve and analyze relational data from your
database.