CSA05 DBMS LAB PRACTICAL RECORD
CSA05 DBMS LAB PRACTICAL RECORD
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:
Output:
Query OK, table created.
Query OK, table altered.
Query OK, table truncated.
Query OK, table dropped.
Theory:
Constraints ensure the integrity of data in tables. Common constraints include PRIMARY KEY,
FOREIGN KEY, NOT NULL, UNIQUE, and CHECK.
Sample Queries:
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:
Output:
1 | HR | 15000
Theory:
UPDATE modifies existing data, and DELETE removes data from the table.
Sample Queries:
Output:
Query OK, 1 row updated.
Query OK, 1 row deleted.
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:
Output:
Privileges granted.
Privileges revoked.
Theory:
The WHERE clause filters records. LIKE allows pattern matching using % and _.
Sample Queries:
Output:
1 | HR | 15000
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
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
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:
Output:
1 | HR | 15000 | 1001 | John
Sample Queries:
Output:
View created.
Index created.
Theory:
AUTO_INCREMENT automatically generates sequential numeric values.
Sample Queries:
Output:
Auto-increment table created.
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.
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.
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.
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.
Sample Queries:
Output:
Cursor declared.
Theory:
Triggers run automatically before/after insert, update, or delete events.
Sample Queries:
Output:
Trigger created.
Theory:
MySQL string functions perform operations on text values.
Sample Queries:
Output:
MyDatabase
Theory:
String functions help in formatting and extracting data.
Sample Queries:
SELECT UPPER('mysql');
Output:
MYSQL
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
Theory:
Demonstrates SQL queries for a simple ticket booking app.
Sample Queries:
Output:
Ticket details for John
Theory:
Manage and query college admission form data.
Sample Queries:
Theory:
Uses SQL to retrieve QR scanned bus ticket data.
Sample Queries:
Output:
Bus ticket details with QR status scanned