Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

DBMS Lab Report

Sample report

Uploaded by

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

DBMS Lab Report

Sample report

Uploaded by

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

LAB 1:

OBJECTIVE:
To understand and draw ER diagram for Library Management System

THEORY:
Entity-Relational (ER) Data Model uses tables to represent the data and the relationship among these data.
Each table has multiple columns and each column is identified by a unique name. It is a low-level model.
ER model describes the design of database in terms of entities and relations between them. Peter Chen
developed the ER diagram in 1976 .The ER data model specifies enterprise schema that represents the
overall logical structure of a database graphically.
ER diagram of Library Management System using online available tool smartdraw.com
LAB 2
OBJECTIVE:
To study different data defination language (DDL) commands in SQL and implement them in database.

THEORY:
SQL commands are extensively used to interact with databases, enabling users to perform a wide range of
actions on database systems. Understanding these commands is crucial for effectively managing and
manipulating data.

Data Definition Language(DDL) is a subset of SQL and a part of DBMS (Database Management System).
DDL consist of Commands to commands like CREATE, ALTER, TRUNCATE and DROP. These
commands are used to create or modify the tables in SQL.

DDL commands:

COMMANDS AND OUTPUT


i. CREATE;
CREATE DATABASE school;

CREATE TABLE students (


student_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
date_of_birth DATE
);
ii. DROP;
DROP TABLE students;
Removes the students table from the database completely.
iii. ALTER;
ALTER TABLE students
ADD email VARCHAR(100);

iv. TRUNCATE;
TRUNCATE TABLE students;
Removes all data from the students table, but the table's structure stays the same.

v. RENAME;
RENAME TABLE students TO pupils;
LAB 3
OBJECTIVE:
To study different data manipulation language (DML) commands in SQL and implement them in database.

THEORY:
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.

COMMANDS AND OUTPUTS:


i. INSERT;
INSERT INTO pupils (student_id, first_name, last_name,
date_of_birth, email)
VALUES
(1, 'John', 'Doe', '2000-01-15', 'john.doe@example.com'),
(2, 'Jane', 'Smith', '1999-06-25', 'jane.smith@example.com'),
(3, 'Alice', 'Johnson', '2001-03-10',
'alice.johnson@example.com');
ii. UPDATE;
UPDATE pupils SET email = 'jane.new@example.com', date_of_birth =
'1999-07-15' WHERE student_id = 2;

iii. DELETE;
DELETE FROM pupils
WHERE student_id = 1;

iv. SELECT:
SELECT * FROM pupils
WHERE student_id = 2;

Retrieves details of a specific pupil (e.g., student_id = 2):


LAB 4
OBJECTIVE:
To study and implement JOIN operators in SQL,

THEORY:
Join operation: It's a fundamental operation in relational databases that allows for the retrieval of
from multiple tables simultaneously. SQL JOIN clause is used to query and access data from multiple
tables by establishing logical relationships between them. It can access data from multiple tables
simultaneously using common key values shared across different tables.

We can use SQL JOIN with multiple tables. It can also be paired with other clauses, the most popular use
will be using JOIN with WHERE clause to filter data retrieval.

The syntax for SQL INNER JOIN is:


SELECT table1.column1,table1.column2,table2.column1,....
FROM table1
INNER JOIN table2
ON table1.matching_column = table2.matching_column;

COMMANDS AND OUTPUT:


i. INNER JOIN

Firstly start by creating two table one we created in previous labs, we will be using that and created another
table name ‘courses’ with respective columns and data were inserted. Now applying JOIN OPERATION.

Course table:

Pupils table:

After JOINING:
SELECT p.first_name, p.last_name, c.course_name
FROM pupils p
INNER JOIN courses c ON p.student_id = c.student_id;
ii. NATURAL JOIN
A NATURAL JOIN is a type of join that automatically matches columns with the same name
in both tables and combines them in the result set. It simplifies joining tables when the column
names and data types are the same and you want to use those columns for the join condition.
Code: SELECT * FROM pupils
NATURAL JOIN courses;
LAB 5
OBJECTIVE:
To study different clauses in SQL.

THEORY:
SQL clauses are essential components of SQL queries that help you retrieve, filter, group, and sort data
from a database. Here are some of the most commonly used SQL clauses.

 SELECT Clause: Specifies the columns to retrieve from a table.


 Example: SELECT column1, column2 FROM table_name;
 FROM Clause: Indicates the table(s) from which to fetch data.
 Example: SELECT column1 FROM table_name;
 WHERE Clause: Filters records based on specified conditions.
 Example: SELECT * FROM table_name WHERE condition;
 JOIN Clauses:
 INNER JOIN: Combines rows with matching values in both tables.
o Example: SELECT * FROM table1 INNER JOIN table2 ON table1.column =
table2.column;
 Like Clauses: used to search for a specified pattern in a column.
 Example: SELECT column1, column2 FROM table_name WHERE column_name LIKE pattern;
Patterns;
o Percent Sign (%): Represents zero or more characters.
o Underscore (_): Represents a single character.

COMMANDS AND OUTPUTS:


We have already discussed select, from, where, join clauses on previous labs, here we discuss about LIKE
clauses.

Demo Table;
1. Example: Retrieve SupplierID, Name, and Address from suppliers table, where supplier name
starts form k.
Command: SELECT SupplierID, Name, Address
FROM Suppliers
WHERE Name LIKE 'Ca%';

2. Example: Retrieve entire table, where address contains OKHLA.


Command: SELECT *
FROM Suppliers
WHERE Address LIKE '%Okhla%';

3. Example: Retrieve SupplierID, Name and Address of supplier whose name contains “ango” in
second substring.
Command: SELECT SupplierID, Name, Address
FROM Suppliers
WHERE Name LIKE '_ango%';
LAB 6
OBJECTIVE:
Solve the given questions using ORACLE LIVE SQL - HR database scheme.

THEORY:
Oracle Live SQL is a web-based platform that allows you to write, run, and share SQL scripts directly in
your browser.

HR database scheme.

QUESTIONS AND OUTPUTS:


1. Display average salary of employees.
2. Display total number of employees working in that office.

3. Display total salary distribution at the end of the month for all employees.

4. Display unique Lastname from employees.


5. Display employees according to department_id in increasing order of department_id.

6. Find total employees working in each department order by total employees.


7. Display total salary of employees working as Stock Clerk.

8. Display departments that possess less than 3 employees.

9. Find employees who are Designated for Purchasing Clerk.


10. Display maximum salary of Purchasing Clerk.

11. Display minimum salary of Sales Manager.

12. Display maximum average salary of employees by job_id.


13. Display minimum average salary of employees by department_id.

14. Display department where sum of salaries is 50000 or greater than 50000.

You might also like