





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Title: Study and Implementation of SQL Data Manipulation Language (DML) Commands ā INSERT, SELECT, UPDATE, and DELETE ā in MS SQL Server. Aim: To study, apply, and analyze SQL DML commands for inserting, retrieving, updating, and deleting data in relational database tables using MS SQL Server, and to evaluate appropriate clauses (WHERE, ORDER BY, GROUP BY, HAVING) for solving real data manipulation problems. Software / Hardware Required: Type Requirement Software MS SQL Server 2019 / 2022, SQL Server Management Studio (SSMS) Operating System Windows 10 / 11 Hardware PC with minimum 4 GB RAM, Intel i3 processor or above Objectives: On completion of this lab session, students will be able to:
ļ· SELECT ā retrieves existing data from one or more tables, optionally filtered, sorted, grouped, or summarized ļ· UPDATE ā modifies values in existing rows ļ· DELETE ā removes existing rows from a table Key characteristics of DML commands: ļ· Transactional nature: DML operations in MS SQL Server are transactional ā they can be wrapped in BEGIN TRANSACTION, COMMIT, and ROLLBACK statements, allowing changes to be undone if an error occurs before they are committed. This is different from most DDL operations, which auto- commit in many database systems. ļ· Row-level operations: DML commands act on rows (also called tuples or records), whereas DDL commands act on the schema (tables, columns, constraints) itself. ļ· Logged operations: Every DML operation (except in special bulk-logged scenarios) is recorded in the transaction log, which supports recovery and auditing ā this is part of why DELETE is slower than TRUNCATE, which is technically a DDL-like operation that bypasses row-by-row logging. ļ· Data integrity enforcement: DML operations are checked against constraints defined during DDL (PRIMARY KEY, FOREIGN KEY, NOT NULL, CHECK, UNIQUE). For example, an INSERT or UPDATE that violates a CHECK or FOREIGN KEY constraint will be rejected by the server. ļ· Order of precedence in a query: When multiple clauses are combined in a SELECT statement, SQL Server logically processes them in this order: FROM ā WHERE ā GROUP BY ā HAVING ā SELECT ā ORDER BY ā even though they are written in a different order. Understanding this helps explain why you can't reference a column alias defined in SELECT inside a WHERE clause, but you can in ORDER BY. Table creation CREATE TABLE DEPT ( Did INT NOT NULL, Dname VARCHAR(50) NOT NULL, Dloc VARCHAR(50), CONSTRAINT PK_DEPT PRIMARY KEY (Did) );
2.1 WHERE Clause Filters rows based on a condition. Supports operators like =, <, >, BETWEEN, IN, LIKE, and IS NULL. SELECT * FROM STUDENT WHERE Rollno BETWEEN 2 AND 4; SELECT * FROM STUDENT WHERE Sname LIKE 'A%'; 2.2 ORDER BY, DISTINCT, TOP SELECT * FROM STUDENT ORDER BY Sname DESC; SELECT DISTINCT Div FROM STUDENT; SELECT TOP 3 * FROM STUDENT ORDER BY Rollno; 2.3 Aggregate Functions, GROUP BY, HAVING Aggregate functions (COUNT, SUM, AVG, MAX, MIN) summarize data across rows. GROUP BY groups rows sharing a value; HAVING filters groups (unlike WHERE, which filters individual rows). SELECT Did, COUNT() AS StudentCount FROM STUDENT GROUP BY Did HAVING COUNT() > 1;
Did Dname Dloc 1 Information Technology 2 - floor 2 Computer Engineering 3 - floor 3 Electronics 1 - floor Erpid Rollno Sname Div Did Gender club_mem 101 1 Aarav Shah A 1 M NO 102 2 Diya Mehta A 1 F YES 103 3 Kabir Rao B 2 M NO 104 4 Ishita Nair B 2 F YES 105 5 Vivaan Joshi A 3 M NO Lab Performance Questions: Read each question carefully, perform the operation on MS SQL Server, verify the output, and write down the exact query you executed by hand in the space provided. Q1. Insert two new department records of your choice into DEPT and display all data of DEPT table. [RBT Level: Apply] Write your query here:
Q6. Display the top 3 students when sorted by Rollno. [RBT Level: Apply] Write your query here: Q7. Analyze the data to find the total number of students in each department. [RBT Level: Analyze] Write your query here: Q8. Update the contact number of any one student of your choice. [RBT Level: Apply] Write your query here: Q9. Update all students of Division 'B' to mark them as club members. [RBT Level: Apply] Write your query here:
Q10. Delete a student record using its Erpid. [RBT Level: Apply] Write your query here: Q11. Evaluate which DML command and clause combination would correctly display students who are NOT club members and belong to Division 'A', then write and execute that query. [RBT Level: Evaluate] Write your query here Results as Print Out: (Annexure ā I) Attach the printed screenshot(s) of query output(s) for each of the above questions in the space below (or on a separate attached sheet).