0% found this document useful (0 votes)
110 views34 pages

DBMS & SQL

DBMS is software that manages databases. A database is a collection of organized data that can be easily accessed. DBMS provides tools to define, manipulate, and retrieve data from the database. It allows multiple users to access the database concurrently. Common types of databases include centralized, distributed, relational, and NoSQL databases. Relational databases organize data into tables and use SQL, while NoSQL databases are more flexible in data structure.

Uploaded by

Sharad Dhumal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
110 views34 pages

DBMS & SQL

DBMS is software that manages databases. A database is a collection of organized data that can be easily accessed. DBMS provides tools to define, manipulate, and retrieve data from the database. It allows multiple users to access the database concurrently. Common types of databases include centralized, distributed, relational, and NoSQL databases. Relational databases organize data into tables and use SQL, while NoSQL databases are more flexible in data structure.

Uploaded by

Sharad Dhumal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 34

DBMS & SQL

DBMS
Database management system is software that is used to manage the database.

What is Database
The database is a collection of inter-related data which is used to retrieve, insert and delete the data efficiently.

It is also used to organize the data in the form of a table, schema, views, and reports, etc.

For example: The college Database organizes the data about the admin, staff, students and faculty etc.
Database Management System

● Database management system is a software which is used to manage the database.


● For example: MySQL, Oracle etc are a very popular commercial database which is used in different applications.
● DBMS provides an interface to perform various operations like database creation, storing data in it, updating data,
creating a table in the database and a lot more.
● It provides protection and security to the database.
● In the case of multiple users, it also maintains data consistency.

DBMS allows users the following tasks:

● Data Definition: It is used for creation, modification, and removal of definition that defines the organization of data
in the database.
● Data Updation: It is used for the insertion, modification, and deletion of the actual data in the database.
● Data Retrieval: It is used to retrieve the data from the database which can be used by applications for various
purposes.
● User Administration: It is used for registering and monitoring users, maintain data integrity, enforcing data security,
dealing with concurrency control, monitoring performance and recovering information corrupted by unexpected
failure.
Characteristics of DBMS
● It uses a digital repository established on a server to store and manage the information.
● It can provide a clear and logical view of the process that manipulates data.
● DBMS contains automatic backup and recovery procedures.
● It contains ACID properties which maintain data in a healthy state in case of failure.
● It can reduce the complex relationship between data.
● It is used to support manipulation and processing of data.
● It is used to provide security of data.
● It can view the database from different viewpoints according to the requirements of the user.
Advantages of DBMS
● Controls database redundancy: It can control data redundancy because it stores all the data in one
single database file and that recorded data is placed in the database.
● Data sharing: In DBMS, the authorized users of an organization can share the data among multiple
users.
● Easily Maintenance: It can be easily maintainable due to the centralized nature of the database
system.
● Reduce time: It reduces development time and maintenance need.
● Backup: It provides backup and recovery subsystems which create automatic backup of data from
hardware and software failures and restores the data if required.
● multiple user interface: It provides different types of user interfaces like graphical user interfaces,
application program interfaces
Disadvantages of DBMS
● Cost of Hardware and Software: It requires a high speed of data processor and large memory size
to run DBMS software.
● Size: It occupies a large space of disks and large memory to run them efficiently.
● Complexity: Database system creates additional complexity and requirements.
● Higher impact of failure: Failure is highly impacted the database because in most of the
organization, all the data stored in a single database and if the database is damaged due to electric
failure or database corruption then the data may be lost forever.
What is Data?
Data is a collection of a distinct small unit of information.

It can be used in a variety of forms like text, numbers, media, bytes, etc.

it can be stored in pieces of paper or electronic memory, etc.

Word 'Data' is originated from the word 'datum' that means 'single piece of information.' It is plural of the word datum.

In computing, Data is information that can be translated into a form for efficient movement and processing.

Data is interchangeable.
What is Database?
A database is an organized collection of data, so that it can be easily accessed and managed.

You can organize data into tables, rows, columns, and index it to make it easier to find relevant information.

Database handlers create a database in such a way that only one set of software program provides access of data to all the
users.

The main purpose of the database is to operate a large amount of information by storing, retrieving, and managing data.

There are many dynamic websites on the World Wide Web nowadays which are handled through databases.

For example, a model that checks the availability of rooms in a hotel. It is an example of a dynamic website that uses a
database.

There are many databases available like MySQL, Sybase, Oracle, MongoDB, Informix, PostgreSQL, SQL Server, etc.

Modern databases are managed by the database management system (DBMS).


SQL or Structured Query Language is used to operate on the data stored in a database.

SQL depends on relational algebra and tuple relational calculus.

A cylindrical structure is used to display the image of a database.


Types of Database
1) Centralized Database
It is the type of database that stores data at a centralized database system.

It comforts the users to access the stored data from different locations through several applications.

These applications contain the authentication process to let users access data securely.

An example of a Centralized database can be Central Library that carries a central database of each library in a college/university.

Advantages of Centralized Database

● It has decreased the risk of data management, i.e., manipulation of data will not affect the core data.
● Data consistency is maintained as it manages data in a central repository.
● It provides better data quality, which enables organizations to establish data standards.
● It is less costly because fewer vendors are required to handle the data sets.

Disadvantages of Centralized Database

● The size of the centralized database is large, which increases the response time for fetching the data.
● It is not easy to update such an extensive database system.
● If any server failure occurs, entire data will be lost, which could be a huge loss.
2) Distributed Database
Unlike a centralized database system, in distributed systems, data is distributed among different database systems of an
organization.

These database systems are connected via communication links. Such links help the end-users to access the data easily.
Examples of the Distributed database are Apache Cassandra, HBase, Ignite, etc.

We can further divide a distributed database system into:

● Homogeneous DDB: Those database systems which execute on the same operating system and use the same
application process and carry the same hardware devices.
● Heterogeneous DDB: Those database systems which execute on different operating systems under different
application procedures, and carries different hardware devices.
Advantages of Distributed Database

● Modular development is possible in a distributed database,


● i.e., the system can be expanded by including new computers
and connecting them to the distributed system.
● One server failure will not affect the entire data set.
3) Relational Database
This database is based on the relational data model, which stores data in the form of rows(tuple) and columns(attributes), and together
forms a table(relation).

A relational database uses SQL for storing, manipulating, as well as maintaining the data. E.F. Codd invented the database in 1970.

Each table in the database carries a key that makes the data unique from others.

Examples of Relational databases are MySQL, Microsoft SQL Server, Oracle, etc.

Properties of Relational Database


There are following four commonly known properties of a relational model known as ACID properties, where:

A means Atomicity: This ensures the data operation will complete either with success or with failure. It follows the 'all or nothing'
strategy. For example, a transaction will either be committed or will abort.

C means Consistency: If we perform any operation over the data, its value before and after the operation should be preserved.

For example, the account balance before and after the transaction should be correct, i.e., it should remain conserved.

I means Isolation: There can be concurrent users for accessing data at the same time from the database.

Thus, isolation between the data should remain isolated. For example, when multiple transactions occur at the same time, one
transaction effects should not be visible to the other transactions in the database.

D means Durability: It ensures that once it completes the operation and commits the data, data changes should remain permanent.
4) NoSQL Database
Non-SQL/Not Only SQL is a type of database that is used for storing a wide range of data sets.

It is not a relational database as it stores data not only in tabular form but in several different ways.

It came into existence when the demand for building modern applications increased.

hus, NoSQL presented a wide variety of database technologies in response to the demands.

Advantages of NoSQL Database

● It enables good productivity in the application development as it is not required to store data in a structured format.
● It is a better option for managing and handling large data sets.
● It provides high scalability.
● Users can quickly access data from the database through key-value.
5) Cloud Database
A type of database where data is stored in a virtual environment and executes over the cloud computing platform.

It provides users with various cloud computing services (SaaS, PaaS, IaaS, etc.) for accessing the database.

There are numerous cloud platforms, but the best options are:

● Amazon Web Services(AWS)


● Microsoft Azure
● Kamatera
● PhonixNAP
● ScienceSoft
● Google Cloud SQL, etc.

6) Object-oriented Databases

7) Hierarchical Databases

8) Network Databases

9) Enterprise Database
What is RDBMS
RDBMS stands for Relational Database Management Systems..

All modern database management systems like SQL, MS SQL Server, IBM DB2, ORACLE, My-SQL and
Microsoft Access are based on RDBMS.

It is called Relational DataBase Management System (RDBMS) because it is based on relational model
introduced by E.F. Codd.

How it works
Data is represented in terms of tuples (rows) in RDBMS.

Relational database is most commonly used database. It contains number of tables and each table has its
own primary key.

Due to a collection of organized set of tables, data can be accessed easily in RDBMS.
What is table
The RDBMS database uses tables to store data.

A table is a collection of related data entries and contains rows and columns to store data.

A table is the simplest example of data storage in RDBMS.

ID Name AGE COURSE

1 Sandeep 25 B.Tech

2 Ajinkya 24 MBA

3 Mayur 23 BTech

4 Rahul 27 MCA

5 Vijay 26 BSC
What is field
Field is a smaller entity of the table which contains specific information about every record in the table.

In the above example, the field in the student table consist of id, name, age, course.

What is row or record


A row of a table is also called record. It contains the specific information of each individual entry in the table.

It is a horizontal entity in the table. For example: The above table contains 5 records.

1 Sandeep 30 B.Tech
What is column
A column is a vertical entity in the table which contains all information associated with a specific field in a table.

For example: "name" is a column in the above table which contains all information about student's name.

Sandeep

Ajay

Mahesh

Atul

Vijay
Database Language
● A DBMS has appropriate languages and interfaces to express database queries and updates.
● Database languages can be used to read, store and update the data in the database.

Types of Database Language


1. Data Definition Language

● DDL stands for Data Definition Language. It is used to define database structure or pattern.
● It is used to create schema, tables, indexes, constraints, etc. in the database.
● Using the DDL statements, you can create the skeleton of the database.
● Data definition language is used to store the information of metadata like the number of tables and schemas, their
names, indexes, columns in each table, constraints, etc.

Here are some tasks that come under DDL:

● Create: It is used to create objects in the database.


● Alter: It is used to alter the structure of the database.
● Drop: It is used to delete objects from the database.
● Truncate: It is used to remove all records from a table.
● Rename: It is used to rename an object.
● Comment: It is used to comment on the data dictionary.

These commands are used to update the database schema that's why they come under Data definition language.
2. Data Manipulation Language

DML stands for Data Manipulation Language.

It is used for accessing and manipulating data in a database. It handles user requests.

Here are some tasks that come under DML:

● Select: It is used to retrieve data from a database.


● Insert: It is used to insert data into a table.
● Update: It is used to update existing data within a table.
● Delete: It is used to delete all records from a table.
● Merge: It performs UPSERT operation, i.e., insert or update operations.
● Call: It is used to call a structured query language or a Java subprogram.
● Explain Plan: It has the parameter of explaining data.
● Lock Table: It controls concurrency.
3. Data Control Language

● DCL stands for Data Control Language. It is used to retrieve the stored or saved data.
● The DCL execution is transactional. It also has rollback parameters.

(But in Oracle database, the execution of data control language does not have the feature of rolling back.)

Here are some tasks that come under DCL:

● Grant: It is used to give user access privileges to a database.


● Revoke: It is used to take back permissions from the user.

4. Transaction Control Language


TCL is used to run the changes made by the DML statement. TCL can be grouped into a logical transaction.

Here are some tasks that come under TCL:

● Commit: It is used to save the transaction on the database.


● Rollback: It is used to restore the database to original since the last Commit.
ACID Properties in DBMS
BMS is the management of data that should remain integrated when any changes are done in it.

It is because if the integrity of the data is affected, whole data will get disturbed and corrupted.
Some SQL Commands
The SQL commands help in creating and managing the
database. DELETE Command

The most common SQL commands which are highly used are This command helps in removing or erasing the saved records
mentioned below: from the database tables. It erases single or multiple tuples
from the tables of the database.
1. CREATE command
2. UPDATE command
SELECT Command
3. DELETE command This command helps in accessing the single or multiple rows
4. SELECT command from one or multiple tables of the database. We can also use
this command with the WHERE clause.
5. DROP command
6. INSERT command DROP Command

CREATE Command This command helps in deleting the entire table, table view, and
other objects from the database.
This command helps in creating the new database, new table,
table view, and other objects of the database. INSERT Command

UPDATE Command This command helps in inserting the data or records into the
database tables. We can easily insert the records in single as
well as multiple rows of the table.
This command helps in updating or changing the stored data
in the database.
SELECT Statement -
1. SELECT Column_Name_1, Column_Name_2, ....., Column_Name_N FROM Table_Name;
2. SELECT * FROM table_name;
3. SELECT UNIQUE/Distinct column_name FROM table_name;

SELECT Statement with WHERE clause


1. SELECT * FROM Name_of_Table WHERE [condition];
2. SELECT * FROM Employee WHERE age = 25;

SQL SELECT Statement with GROUP BY clause


SELECT column_Name_1, ....., column_Name_N aggregate_function_name(column_Name2) FROM
table_name GROUP BY column_Name1.

1. SELECT COUNT (Car_Name), Car_Price FROM Cars_Details GROUP BY Car_Price;


SELECT Statement with ORDER BY clause
The ORDER BY clause with the SQL SELECT statement shows the records or rows in a sorted manner.

The ORDER BY clause arranges the values in both ascending and descending order.

Few database systems arrange the values of column in ascending order by default.

SQL SELECT COUNT


The SQL COUNT() is a function that returns the number of records of the table in the output.

This function is used with the SQL SELECT statement.

SQL Count() Function With WHERE Clause


We can also use the Count() function with the WHERE clause. The Count Function with WHERE clause in the SELECT
statement shows those records that matched the specified criteria.
SQL Count Function With DISTINCT keyword
The DISTINCT keyword with the COUNT function shows only the numbers of unique rows of a column.

SQL SELECT TOP


The SELECT TOP statement in SQL shows the limited number of records or rows from the database table.

The TOP clause in the statement specifies how many rows are returned.

It shows the top N number of rows from the tables in the output.

This clause is used when there are thousands of records stored in the database tables.

LIMIT Clause in MySQL


1. SELECT column_Name1,column_Name2, ....., column_NameN FROM table_name LIMIT value;

In the syntax, we have to specify the value after the LIMIT keyword.

The value denotes the number of rows to be shown from the top in the output.
SQL SELECT FIRST
The SQL first() function is used to return the first value of the selected column.

1. SELECT FIRST(column_name) FROM table_name;

SQL SELECT LAST


The LAST() function in Structured Query Language shows the last value from the specified column of the table.

LIMIT Clause in MySQL


1. SELECT column_Name FROM Table_Name ORDER BY Column_Name DESC LIMIT 1;

ROWNUM keyword in Oracle


The syntax for accessing the last record from the Oracle database is given below:

1. SELECT Column_Name FROM Table_Name ORDER BY Column_Name DESC WHERE ROWNUM <=1;

In this Oracle syntax, we have to specify the ROWNUM keyword, which is less than and equal to 1.

In Oracle, the ROWNUM keyword is used in the WHERE clause for retrieving the last record from the table.
SQL SELECT RANDOM
The SQL SELECT RANDOM() function returns the random row. It can be used in online exam to display the random
questions.

There are a lot of ways to select a random record or row from a database table.

Each database server needs different SQL syntax.

If you want to select a random row with MY SQL:

1. SELECT column FROM table


2. ORDER BY RAND ( )
3. LIMIT 1
SQL JOIN
As the name shows, JOIN means to combine something. In case of SQL, JOIN means "to combine two or more tables".

The SQL JOIN clause takes records from two or more tables in a database and combines it together.

ANSI standard SQL defines five types of JOIN :

1. inner join,
2. left outer join,
3. right outer join,
4. full outer join, and
5. cross join.

In the process of joining, rows of both tables are combined in a single table.
Why SQL JOIN is used?
If you want to access more than one table through a select statement.

If you want to combine two or more table then SQL JOIN statement is used .

it combines rows of that tables in one table and one can retrieve the information by a SELECT statement.

The joining of two or more tables is based on common field between them.

SQL INNER JOIN also known as simple join is the most common type of join.
SQL OUTER JOIN
In the SQL outer JOIN all the content of the both tables are integrated together either they are matched or not.

If you take an example of employee table

Outer join of two types:

1.Left outer join (also known as left join): this join returns all the rows from left table combine with the matching rows of the
right table. If you get no matching in the right table it returns NULL values.

2.Right outer join (also known as right join): this join returns all the rows from right table are combined with the matching
rows of left table .If you get no column matching in the left table .it returns null value.

This diagram shows the different type of joins:

You might also like