Professional Documents
Culture Documents
Data Base Management System Lab4
Data Base Management System Lab4
Data Base Management System Lab4
Database
A database management system (DBMS) is a software application
that enables users to efficiently store, organize, manage, and retrieve
vast amounts of data. It provides a systematic approach to handling
data by acting as an intermediary between the user and the underlying
database, allowing for convenient data manipulation, storage
optimization, data security, and data integrity. DBMSs offer a wide
range of functionalities such as data modeling, query processing,
transaction management, and user access control, enabling businesses
and organizations to effectively handle their data needs and make
informed decisions based on the stored information.
Some popular examples of DBMS include Oracle Database, MySQL,
Microsoft SQL Server, PostgreSQL, and MongoDB.
SQL
SQL stands for Structured Query Language. It is a standard
programming language used for managing and manipulating
relational databases. SQL provides a set of commands and syntax that
allows users to interact with the database, perform various operations,
and retrieve information.
SQL uses commands like SELECT, INSERT, UPDATE, and DELETE
to perform these operations. You can use SQL to create tables that
define the structure of the data, specify conditions to filter the data
you want to retrieve, and make changes to the data as needed.
It's important to note that SQL is a standardized language, but
different database management systems may have their own specific
variations and additional features.
However, the core concepts and syntax of SQL remain consistent
across different systems.
SQL PROCESSING
When we are executing an SQL command for any RDBMS, the
system determines the best way to carry out your request and SQL
engine figures out how to interpret the task.
There are various components included in this process. These
components are −
• Query Dispatcher
• Optimization Engines
• Classic Query Engine
• SQL Query Engine, etc.
A classic query engine handles all the non-SQL queries, but a SQL
query engine won't handle logical files. Following is a simple diagram
showing the SQL Architecture -
Types of SQL
There are several types or categories of SQL that serve different
purposes or work with specific types of databases. Here are some
common types of SQL:
1. Data Definition Language (DDL): DDL SQL statements are used to
define and manage the structure of the database objects. They include
commands such as CREATE, ALTER, and DROP, which are used to
create, modify, or delete tables, indexes, views, and other database
objects.
2. Data Manipulation Language (DML): DML SQL statements are
used to manipulate the data stored in the database. They include
commands such as SELECT, INSERT, UPDATE, and DELETE.
These statements are used to retrieve, add, modify, or remove data
from the database tables.
3. Data Control Language (DCL): DCL SQL statements are used to
manage the security and access privileges of the database. They
include commands such as GRANT and REVOKE, which grant or
revoke permissions to users and control their access to database
objects.
4. Transaction Control Language (TCL): TCL SQL statements are
used to manage transactions within a database. They include
commands such as COMMIT, ROLLBACK, and SAVEPOINT. These
statements allow you to control the atomicity, consistency, isolation,
and durability (ACID properties) of database transactions.
5. Data Query Language (DQL): DQL SQL statements are primarily
focused on retrieving and querying data from the database. The most
commonly used DQL statement is SELECT, which allows you to
retrieve specific data based on specified conditions and perform
complex queries using joins, filtering, sorting, and aggregating.
6. Data Definition Extensions (DDE): DDE SQL statements are
specific to certain database systems and provide extensions beyond
Trigger in SQL
A trigger in MySQL is a set of SQL statements that reside in a system
catalog. It is a special type of stored procedure that is invoked
automatically in response to an event. Each trigger is associated with
a table, which is activated on any DML statement such as INSERT,
UPDATE, or DELETE.
A trigger is called a special procedure because it cannot be called
directly like a stored procedure. The main difference between the
trigger and procedure is that a trigger is called automatically when a
data modification event is made against a table. In contrast, a stored
procedure must be called explicitly.
Generally, triggers are of two types according to the SQL standard:
row-level triggers and statement-level triggers.
Row-Level Trigger: It is a trigger, which is activated for each row by
a triggering statement such as insert, update, or delete. For example, if
a table has inserted, updated, or deleted multiple rows, the row trigger
is fired automatically for each row affected by the insert, update,
or delete statement.
Statement-Level Trigger: It is a trigger, which is fired once for each
event that occurs on a table regardless of how many rows are inserted,
updated, or deleted.
MY SQL JOINS
MySQL JOINS are used with SELECT statement. It is used to
retrieve data from multiple tables. It is performed whenever you need
to fetch records from two or more tables.
There are three types of MySQL joins:
o MySQL INNER JOIN (or sometimes called simple join)
o MySQL LEFT OUTER JOIN (or sometimes called LEFT JOIN)
o MySQL RIGHT OUTER JOIN (or sometimes called RIGHT
JOIN)
Syntax:
1. SELECT columns
2. FROM table1
3. LEFT [OUTER] JOIN table2
4. ON table1.column = table2.column;
Syntax:
1. SELECT columns
2. FROM table1
3. RIGHT [OUTER] JOIN table2
4. ON table1.column = table2.column;
QUERIES
• Write a SQL query to create and use a database:-
Projects
Project-1
Library Management System:-Create the following schema, enter at
least 5 records in each table and answer the queries given below.
LibraryBooks (Accession number, Title, Author, Department,
PurchaseDate, Price) IssuedBooks (Accession number, Borrower)
a) Identify primary and foreign keys. Create the tables and insert at
least 5 records in each table.
e) List all books that belong to “CSE” department and are written by
author “Navathe”.
g) List all books which have a price less than 500 or purchased
between “01/01/2015” and “01/01/2019”.
*********************************************
Project-2
Write SQL queries to create three different tables named Salesman,
Customer and Orders respectively with the data given and then
perform the given queries:-
a)Write a SQL query to create table Salesman:-
Q1.Write a SQL query to find the salespeople and customers who live
in the same city. Return customer name, salesperson name and
salesperson city.
Q2. Write a SQL query to locate all the customers and the salesperson
who works for them. Return customer name, and salesperson name.
Q5. write a SQL query to find those customers where each customer
has a grade and is served by a salesperson who belongs to a city.
Return cust_name as "Customer", grade as "Grade".
Q6. Write a SQL query to find all orders executed by the salesperson
and ordered by the customer whose grade is greater than or equal to
200. Compute purch_amt*commission as “Commission”. Return
customer name, commission as “Commission%” and Commission.
*********************************************