Docsity

DIGITAL CIRCUIT DESIGN, Exercises of Data Compression

Toggle sidebar
bg1
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:
1. Apply INSERT, SELECT, UPDATE, and DELETE commands to manipulate data stored in
relational tables. (RBT Level: Apply)
2. Analyze the effect of filtering (WHERE), sorting (ORDER BY), and aggregate operations
(GROUP BY, HAVING) on query results to extract meaningful information. (RBT Level: Analyze)
3. Evaluate and select the most appropriate DML command, clause, or combination of clauses
required to solve a given real-world data manipulation problem. (RBT Level: Evaluate)
Theory:
Data Manipulation Language (DML) is the subset of SQL used to manage data stored within
existing database objects. Unlike DDL, which defines and modifies the structure of database objects
(tables, schemas, constraints), DML deals with the actual rows of data held inside those structures
— inserting new records, retrieving them, modifying them, and removing them. Because DML
operates on data rather than structure, it is used far more frequently than DDL in day-to-day database
operations, forming the backbone of virtually every application that reads or writes to a database.
The four core DML commands are:
ļ‚· INSERT — adds new rows of data into a table
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download DIGITAL CIRCUIT DESIGN and more Exercises Data Compression in PDF only on Docsity!

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:

  1. Apply INSERT, SELECT, UPDATE, and DELETE commands to manipulate data stored in relational tables. (RBT Level: Apply)
  2. Analyze the effect of filtering (WHERE), sorting (ORDER BY), and aggregate operations (GROUP BY, HAVING) on query results to extract meaningful information. (RBT Level: Analyze)
  3. Evaluate and select the most appropriate DML command, clause, or combination of clauses required to solve a given real-world data manipulation problem. (RBT Level: Evaluate) Theory: Data Manipulation Language (DML) is the subset of SQL used to manage data stored within existing database objects. Unlike DDL, which defines and modifies the structure of database objects (tables, schemas, constraints), DML deals with the actual rows of data held inside those structures — inserting new records, retrieving them, modifying them, and removing them. Because DML operates on data rather than structure, it is used far more frequently than DDL in day-to-day database operations, forming the backbone of virtually every application that reads or writes to a database. The four core DML commands are: ļ‚· INSERT — adds new rows of data into a table

ļ‚· 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;

  1. UPDATE Modifies existing rows in a table. A WHERE clause restricts which rows are affected; omitting it updates every row. Syntax: UPDATE table_name SET col1 = val1, col2 = val2, ... WHERE condition; Example: UPDATE STUDENT SET club_mem = 'YES' WHERE Erpid = 101;
  2. DELETE Removes existing rows from a table. Like UPDATE, it should almost always include a WHERE clause to avoid removing all data. Syntax: DELETE FROM table_name WHERE condition; Example: DELETE FROM STUDENT WHERE Erpid = 104; Data Given for Lab Performance: Create the DEPT and STUDENT tables (as designed in the DDL lab) and insert the following sample data before attempting the questions below.

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).