0% found this document useful (0 votes)
9 views9 pages

CSA05 DBMS LAB PRACTICAL RECORD

The document outlines a series of experiments related to Database Management Systems (DBMS) focusing on various SQL commands and concepts. It covers Data Definition Language (DDL), Data Manipulation Language (DML), Transaction Control Language (TCL), and advanced topics such as triggers, stored procedures, and user-defined functions. Each experiment includes theoretical explanations, sample queries, and expected outputs to demonstrate practical applications of SQL in database management.

Uploaded by

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

CSA05 DBMS LAB PRACTICAL RECORD

The document outlines a series of experiments related to Database Management Systems (DBMS) focusing on various SQL commands and concepts. It covers Data Definition Language (DDL), Data Manipulation Language (DML), Transaction Control Language (TCL), and advanced topics such as triggers, stored procedures, and user-defined functions. Each experiment includes theoretical explanations, sample queries, and expected outputs to demonstrate practical applications of SQL in database management.

Uploaded by

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

CSA05 DBMS LAB PRACTICAL RECORD

Experiment 1: DDL Commands (Create, Alter, Truncate, Drop)

Theory:
DDL (Data Definition Language) commands are used to define and modify database structures
such as tables, schemas, and indexes. Examples include CREATE, ALTER, TRUNCATE, and DROP.

Sample Queries:

CREATE TABLE Students (


ID INT PRIMARY KEY,
Name VARCHAR(50)
);

ALTER TABLE Students ADD Age INT;

TRUNCATE TABLE Students;

DROP TABLE Students;

Output:
Query OK, table created.
Query OK, table altered.
Query OK, table truncated.
Query OK, table dropped.

Experiment 2: Implementing Constraints

Theory:
Constraints ensure the integrity of data in tables. Common constraints include PRIMARY KEY,
FOREIGN KEY, NOT NULL, UNIQUE, and CHECK.

Sample Queries:

CREATE TABLE Department (


DeptID INT PRIMARY KEY,
DeptName VARCHAR(50) NOT NULL,
Budget INT CHECK (Budget > 10000)
);

Output:
Query OK, table created with constraints.
Experiment 3: Insert and Select Statements

Theory:
INSERT adds data to a table, while SELECT retrieves it. These are the most common DML (Data
Manipulation Language) operations.

Sample Queries:

INSERT INTO Department VALUES (1, 'HR', 15000);


SELECT * FROM Department;

Output:
1 | HR | 15000

Experiment 4: Update and Delete Statements

Theory:
UPDATE modifies existing data, and DELETE removes data from the table.

Sample Queries:

UPDATE Department SET Budget = 20000 WHERE DeptID = 1;


DELETE FROM Department WHERE DeptID = 1;

Output:
Query OK, 1 row updated.
Query OK, 1 row deleted.

Experiment 5: Transaction Control (COMMIT, ROLLBACK, SAVEPOINT)

Theory:
TCL (Transaction Control Language) commands control transactions. COMMIT saves changes,
ROLLBACK undoes them, and SAVEPOINT sets a point to rollback to.

Sample Queries:

START TRANSACTION;
INSERT INTO Department VALUES (2, 'IT', 18000);
SAVEPOINT sp1;
ROLLBACK TO sp1;
COMMIT;

Output:
Transaction started, savepoint set, rollback completed, transaction committed.
Experiment 6: Grant and Revoke Permissions

Theory:
GRANT gives privileges to users, and REVOKE removes them.

Sample Queries:

GRANT SELECT, INSERT ON Department TO 'user1'@'localhost';


REVOKE INSERT ON Department FROM 'user1'@'localhost';

Output:
Privileges granted.
Privileges revoked.

Experiment 7: WHERE Clause and Pattern Matching

Theory:
The WHERE clause filters records. LIKE allows pattern matching using % and _.

Sample Queries:

SELECT * FROM Department WHERE DeptName LIKE 'H%';

Output:
1 | HR | 15000

Experiment 8: BETWEEN, IN and Aggregate Functions

Theory:
BETWEEN checks values within a range, IN checks multiple values, and aggregate functions
(COUNT, SUM, AVG) compute over sets.

Sample Queries:

SELECT COUNT(*) FROM Department WHERE Budget BETWEEN 10000 AND 20000;

Output:
2
Experiment 9: GROUP BY, HAVING and ORDER BY

Theory:
GROUP BY aggregates rows, HAVING filters groups, and ORDER BY sorts results.

Sample Queries:

SELECT DeptName, COUNT(*) FROM Department GROUP BY DeptName HAVING COUNT(*) >
1 ORDER BY DeptName;

Output:
Finance | 2

Experiment 10: Subqueries and Correlated Subqueries

Theory:
Subqueries are nested queries. Correlated subqueries depend on outer queries.

Sample Queries:

SELECT DeptName FROM Department WHERE DeptID IN (SELECT DeptID FROM Employee);

Output:
IT

Experiment 11: JOINS (Equi, Inner, Outer)

Theory:
Joins combine rows from two or more tables. EquiJoins use equality. Inner Joins return matched
rows. Outer Joins return unmatched rows too.

Sample Queries:

SELECT * FROM Department d JOIN Employee e ON d.DeptID = e.DeptID;

Output:
1 | HR | 15000 | 1001 | John

Experiment 12: VIEWS and INDEXES


Theory:
Views are virtual tables. Indexes improve query speed.

Sample Queries:

CREATE VIEW view_dept AS SELECT DeptName FROM Department;


CREATE INDEX idx_budget ON Department(Budget);

Output:
View created.
Index created.

Experiment 13: AUTO_INCREMENT Property

Theory:
AUTO_INCREMENT automatically generates sequential numeric values.

Sample Queries:

CREATE TABLE Serial (


ID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(20)
);

Output:
Auto-increment table created.

Experiment 14: REPEAT and WHILE Loops

Theory:
REPEAT runs a block until a condition is true. WHILE checks before each iteration.

Sample Queries:

SET @i = 0;
REPEAT SET @i = @i + 1; UNTIL @i > 5 END REPEAT;

Output:
Values incremented to 5.

Experiment 15: CASE and LOOP Statements


Theory:
CASE handles conditional logic. LOOP runs repeatedly until EXIT.

Sample Queries:

SET @i = 0;
LOOP SET @i = @i + 1; IF @i > 5 THEN LEAVE LOOP; END IF; END LOOP;

Output:
Loop exited after 5 iterations.

Experiment 16: Stored Procedures

Theory:
Stored procedures encapsulate SQL logic and can be called by name.

Sample Queries:

DELIMITER //
CREATE PROCEDURE greet() BEGIN SELECT 'Hello'; END;//
DELIMITER ;

Output:
Procedure created.

Experiment 17: User Defined Functions

Theory:
Functions return single values and can be used in SQL expressions.

Sample Queries:

DELIMITER //
CREATE FUNCTION getOne() RETURNS INT BEGIN RETURN 1; END;//
DELIMITER ;

Output:
Function created.

Experiment 18: Cursors


Theory:
Cursors allow row-by-row processing of result sets.

Sample Queries:

DECLARE cur CURSOR FOR SELECT DeptName FROM Department;

Output:
Cursor declared.

Experiment 19: Triggers

Theory:
Triggers run automatically before/after insert, update, or delete events.

Sample Queries:

CREATE TRIGGER trg_upper BEFORE INSERT ON Department


FOR EACH ROW SET NEW.DeptName = UPPER(NEW.DeptName);

Output:
Trigger created.

Experiment 20: String Functions (REPLACE, REVERSE, RPAD)

Theory:
MySQL string functions perform operations on text values.

Sample Queries:

SELECT REPLACE('MySQL', 'SQL', 'Database');

Output:
MyDatabase

Experiment 21: String Functions (SUBSTR, UPPER, LOWER, TRIM, LENGTH)

Theory:
String functions help in formatting and extracting data.

Sample Queries:
SELECT UPPER('mysql');

Output:
MYSQL

Experiment 22: PHP - MySQL Connection

Theory:
PHP connects to MySQL using mysqli or PDO for dynamic web apps.

Sample Queries:

<?php
$conn = new mysqli('localhost', 'root', '', 'test');
if ($conn) echo 'Connected';
?>

Output:
Connected

Experiment 23: Case Study - Ticket Booking System

Theory:
Demonstrates SQL queries for a simple ticket booking app.

Sample Queries:

SELECT * FROM tickets WHERE user = 'John';

Output:
Ticket details for John

Experiment 24: Case Study - College Admission Form

Theory:
Manage and query college admission form data.

Sample Queries:

SELECT * FROM admissions WHERE name LIKE 'A%';


Output:
Admission entries starting with 'A'

Experiment 25: Case Study - QR Bus Ticket Booking

Theory:
Uses SQL to retrieve QR scanned bus ticket data.

Sample Queries:

SELECT * FROM tickets WHERE QR_status='Scanned';

Output:
Bus ticket details with QR status scanned

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