0% found this document useful (0 votes)
13 views

DBMS Dipanshu LabFileE

computer fundation lab -3TGHGTHYT

Uploaded by

YOGENDRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

DBMS Dipanshu LabFileE

computer fundation lab -3TGHGTHYT

Uploaded by

YOGENDRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

SHRI RAMSWAROOP

MEMORIAL UNIVERSITY

DATABASE MANAGEMENT SYSTEM

(UCS 3201)
LAB FILE
SESSION: 2024-2025

SUBMITTED TO: SUBMITTED BY:


MRS. SWETA SINGH NAME: Dipanshu Jha
ASSISTANT PROFESSOR ROLL NO.: 202310101310036
GROUP: BCA-3A
INDEX

FACULTY
S.NO NAME OF ACTIVITY DATE REMARKS
SIGNATURE

Queries for DDL and


1
DML commands
SQL Queries Using
2
Logical Operators
SQL Queries Using SQL
3
Operators
SQL Queries Using
4 Character, Number, Date,
and Group Functions
SQL Queries For
5
Relational Algebra
SQL Queries For
6 Extracting Data From
More Than One Table
SQL Queries For Sub
7
Queries, Nested Queries
Write Program Of
8
PL/SQL
Concepts for Rollback,
9 Commit, Savepoints &
Checkpoints
Create VIEWS,
10 CURSORS And
TRIGGERS
Lab Activity 1
 Write the queries for Data Definition and Data
Manipulation Language

1. Data Definition Language (DDL) Queries

 CREATE TABLE
Syntax:

CREATE TABLE table_name (


column1 datatype constraint,
column2 datatype constraint,
...
);

Example Query:

CREATE TABLE Employees (


EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Department VARCHAR(50),
Salary DECIMAL(10, 2)
);

CREATE TABLE Departments (


DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(50)
);

EMPLOYEE TABLE:-

DEPARTMENT TABLE:-

 ALTER TABLE
Syntax:

ALTER TABLE table_name


ADD (column_name datatype constraint);
Example Query:

ALTER TABLE Employees


ADD Email VARCHAR(100);

OUTPUT:-

 TRUNCATE TABLE
Syntax:

TRUNCATE TABLE table_name;

Example Query:

TRUNCATE TABLE Employees;

OUTPUT:-

 DROP TABLE
Syntax:

DROP TABLE table_name;

Example Query:

DROP TABLE Employees;

2. Data Manipulation Language (DML) Queries

 INSERT INTO
Syntax:

INSERT INTO table_name (column1, column2, ...)


VALUES (value1, value2, ...);

Example Query:

INSERT INTO Employees (EmployeeID, FirstName, LastName, Department, Salary,


Email)
VALUES
(1, 'Nikhil', 'Kapoor', 'HR', 51500.00, 'nikhil.kapoor@example.com'),
(2, 'Sneha', 'Joshi', 'IT', 64500.00, 'sneha.joshi@example.com'),
(3, 'Aryan', 'Mehta', 'Finance', 70500.00, 'aryan.mehta@example.com'),
(4, 'Zoya', 'Ali', 'Marketing', 53500.00, 'zoya.ali@example.com'),
(5, 'Raj', 'Malhotra', 'Sales', 61500.00, 'raj.malhotra@example.com'),
(6, 'Tara', 'Chopra', 'HR', 52500.00, 'tara.chopra@example.com'),
(7, 'Karan', 'Bhatia', 'IT', 67500.00, 'karan.bhatia@example.com'),
(8, 'Ishita', 'Reddy', 'Finance', 73500.00, 'ishita.reddy@example.com'),
(9, 'Ravi', 'Shah', 'Marketing', 55500.00, 'ravi.shah@example.com'),
(10, 'Neha', 'Bhatt', 'Sales', 60500.00, 'neha.bhatt@example.com');

INSERT INTO Departments (DepartmentID, DepartmentName)


VALUES
(10, 'HR'),
(20, 'Finance'),
(30, 'Engineering');

OUTPUT:-

EMPLOYEES TABLE

DEPARTMENT TABLE

 UPDATE
Syntax:

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Example Query:

UPDATE Employees
SET Salary = 55000
WHERE EmployeeID = 1;

OUTPUT:-
 DELETE
Syntax:

DELETE FROM table_name


WHERE condition;

Example Query:

DELETE FROM Employees


WHERE EmployeeID = 10;

OUTPUT:-
Lab Activity 2
 Write SQL Queries Using Logical Operators
 AND Operator
Syntax:

SELECT column1, column2, ...


FROM table_name
WHERE condition1 AND condition2;

Example Query:

SELECT FirstName, LastName


FROM Employees
WHERE Salary > 50000 AND Department = "IT";

OUTPUT:-

 OR Operator
Syntax:

SELECT column1, column2, ...


FROM table_name
WHERE condition1 OR condition2;

Example Query:

SELECT FirstName, LastName


FROM Employees
WHERE Department = "IT" OR Department = "Marketing";

OUTPUT:-

 NOT Operator
Syntax:

SELECT column1, column2, ...


FROM table_name
WHERE NOT condition;

Example Query:

SELECT FirstName, LastName


FROM Employees
WHERE NOT Department = "IT";

OUTPUT:-
Lab Activity 3
 Write SQL Queries Using SQL Operators
 Comparison Operators
Syntax:

SELECT column1, column2, ...


FROM table_name
WHERE column1 operator value;

Example Query:

SELECT FirstName, LastName


FROM Employees
WHERE Salary > 50000;

OUTPUT:-

 Arithmetic Operators
Syntax:

SELECT column1 + column2 AS result


FROM table_name;

Example Query:

SELECT FirstName, Salary, Salary * 0.1 AS Bonus


FROM Employees;

OUTPUT:-
 String Operators
Syntax:

SELECT CONCAT(coulmn1, ' ', column2) AS concatenated_column


FROM table_name;

Example Query:

SELECT CONCAT(FirstName, ' ', LastName) AS FullName


FROM Employees;

OUTPUT:-
Lab Activity 4
 Write SQL Queries Using Character, Number, Date, and
Group Functions

1. Character Functions

 UPPER and LOWER


Syntax:

UPPER(string)
LOWER(string)

Example Query:

SELECT UPPER(FirstName) AS UpperFirstName, LOWER(LastName) AS LowerLastName


FROM Employees;

OUTPUT:-

2. Number Functions

 ROUND
Syntax:

ROUND(number, decimal_places)

Example Query:

SELECT Salary, ROUND(Salary, -3) AS RoundedSalary


FROM Employees;

OUTPUT:-
3. Group Functions

 AVERAGE
Syntax:

SELECT AVG(column_name)
FROM table_name
WHERE condition;

Example Query:

SELECT Department, AVG(Salary) AS AvgSalary


FROM Employees
GROUP BY Department;

OUTPUT:-

 SUM
Syntax:

SELECT SUM(column_name)
FROM table_name
WHERE condition;

Example Query:

-- Sum of all employee salaries


SELECT Department, SUM(Salary) AS TotalSalaries
FROM Employees
GROUP BY Department;

OUTPUT:-
 COUNT
Syntax:

SELECT COUNT(column_name)
FROM table_name
WHERE condition;

Example Query:

-- Count the total number of employees


SELECT Department, COUNT(EmployeeID) AS TotalEmployees
FROM Employees
GROUP BY Department;

OUTPUT:-

 MIN
Syntax:

SELECT MIN(column_name)
FROM table_name
WHERE condition;

Example Query:

-- Minimum salary among employees


SELECT Department, MIN(Salary) AS MinimumSalary
FROM Employees
GROUP BY Department;

OUTPUT:-
 MAX
Syntax:

SELECT MAX(column_name)
FROM table_name
WHERE condition;

Example Query:

-- Maximum salary among employees


SELECT Department, MAX(Salary) AS MaximumSalary
FROM Employees
GROUP BY Department;

OUTPUT:-

 FIRST Element By Using LIMIT


Syntax:

SELECT column1, column2, ...


FROM table_name
ORDER BY column_name ASC
LIMIT 1;

Example Query:

-- First employee by EmployeeID


SELECT FirstName, LastName
FROM Employees
ORDER BY EmployeeID ASC
LIMIT 1;

OUTPUT:-

 LAST Element By Using LIMIT


Syntax:

SELECT column1, column2, ...


FROM table_name
ORDER BY column_name DESC
LIMIT 1;
Example Query:

-- First employee by EmployeeID


SELECT FirstName, LastName
FROM Employees
ORDER BY EmployeeID DESC
LIMIT 1;

OUTPUT:-

 GROUP_CONCAT
Syntax:

SELECT GROUP_CONCAT(column_name SEPARATOR 'separator')


FROM table_name
GROUP BY column_name;

Example Query:

-- List all employees in each department


SELECT Department, GROUP_CONCAT(FirstName SEPARATOR ', ') AS Employees
FROM Employees
GROUP BY Department;

OUTPUT:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy