Assignement 2 (DML)

Oct 31, 2025
Updated 12 hours ago
4 min read

SQL DML: Update, Delete, Filter and Sort Data

In the previous assignment, we created a client_master table and inserted records into it. Now we go one step further — actually working with that data. This post covers DML (Data Manipulation Language): how to update rows, delete them, filter with conditions, sort results, and use pattern matching.


What is DML?

DML stands for Data Manipulation Language. While DDL defines the structure of your database, DML is what you use day-to-day — reading, changing, and removing the actual data inside your tables.

There are two flavors of DML:

Type

What it means

Procedural DML

You specify what data you need and how to get it

Non-Procedural DML

You only specify what you need — the database figures out how

SQL falls into the non-procedural category, which is what makes it approachable even for beginners. For a broader understanding of how databases work underneath, check out this DBMS overview.


UPDATE — Changing Existing Data

When you want to modify specific values in a table without touching the rest of the rows, UPDATE is what you reach for.

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

Always use a WHERE clause with UPDATE. Without it, every single row in the table gets changed — which is almost never what you want.


DELETE — Removing Rows

To remove all rows from a table:

sql
DELETE FROM table_name;

To remove only specific rows:

sql
DELETE FROM table_name
WHERE condition;

Same rule applies here — skip the WHERE and you wipe the entire table.


WHERE Clause — Filtering Rows

The WHERE clause is how you tell SQL which rows to work with. It works with SELECT, UPDATE, and DELETE alike.

sql
SELECT column1, column2
FROM table_name
WHERE condition;

LIKE — Pattern Matching

When you don't know the exact value but know what it looks like, use LIKE:

Symbol

Meaning

%

Zero or more characters

_

Exactly one character

So LIKE '_a%' means: any value where the second character is a.

Logical Operators

Operator

Meaning

AND

All conditions must be true

OR

At least one condition must be true

NOT

Excludes matching values


ORDER BY — Sorting Results

By default, SQL returns rows in no guaranteed order. Use ORDER BY to sort:

sql
SELECT * FROM table_name
ORDER BY column_name ASC|DESC;

ASC is ascending (default), DESC is descending. You can sort by multiple columns too — just comma-separate them.


Column Alias — Renaming Output Columns

Sometimes the column name in the table isn't what you want to show in the result. Use AS to rename it in the output:

sql
SELECT column_name AS alias_name FROM table_name;

This doesn't change the actual column — just what it's called in the result set.


Lab Assignment: Queries on client_master

All queries below use the client_master table from Assignment 1. Here's the data we're starting with:

client_no

name

city

pincode

state

bal_due

0001

Ivan

Bombay

400054

Maharashtra

15000

0002

Vandana

Madras

780001

Tamilnadu

0

0003

Pramada

Bombay

400057

Maharashtra

5000

0004

Basu

Bombay

NULL

Maharashtra

0

0005

Ravi

Delhi

100001

NULL

2000

0006

Rukmini

Bombay

400050

Maharashtra

0

Important: Some queries below modify the data (UPDATE, DELETE). The expected outputs for later queries reflect those earlier changes — run them in order.


i. Update bal_due of client 0002 to 10000

sql
UPDATE client_master
SET bal_due = 10000
WHERE client_no = '0002';

Expected output (updated row):

plaintext
0002 | Vandana | Madras | 780001 | Tamilnadu | 10000

ii. Delete the record for client 0001

sql
DELETE FROM client_master
WHERE client_no = '0001';

Row with client_no = '0001' (Ivan) is permanently removed from the table.


iii. Change city of client 0005 to Bombay

sql
UPDATE client_master
SET city = 'Bombay'
WHERE client_no = '0005';

Expected output (updated row):

plaintext
0005 | Ravi | Bombay | 100001 | NULL | 2000

iv. Clients with bal_due > 5000, show computed balance

This one uses a column alias — (bal_due * 15) is displayed as Updated Balance in the output.

sql
SELECT name, bal_due, (bal_due * 15) AS "Updated Balance"
FROM client_master
WHERE bal_due > 5000;

Expected output:

plaintext
Vandana | 10000 | 150000

Ivan's row was deleted earlier, so only Vandana qualifies.


v. Clients whose city has 'a' as the second letter

sql
SELECT * FROM client_master
WHERE city LIKE '_a%';

Expected output:

plaintext
Vandana | Madras | ...

After the earlier update, Ravi's city is now Bombay — second letter is o, so it doesn't match. Only Madras qualifies.


vi. Clients whose name has 'a' as the second letter

sql
SELECT name
FROM client_master
WHERE name LIKE '_a%';

Expected output:

plaintext
Vandana
Basu

vii. All clients sorted alphabetically by name

sql
SELECT * FROM client_master
ORDER BY name ASC;

Expected output:

plaintext
Basu, Pramada, Ravi, Rukmini, Vandana

viii. Distinct cities across all clients

sql
SELECT DISTINCT city FROM client_master;

Expected output:

plaintext
Bombay
Madras

Delhi was changed to Bombay in query iii, so it no longer appears.


ix. Clients where both pincode AND state are NULL

sql
SELECT * FROM client_master
WHERE pincode IS NULL AND state IS NULL;

Expected output: No rows returned.

Client 0004 has a NULL pincode but has a state (Maharashtra). Client 0005 has a NULL state but has a pincode. Neither satisfies both conditions being NULL simultaneously.


x. Clients with balance between 10000 and 15000

sql
SELECT * FROM client_master
WHERE bal_due BETWEEN 10000 AND 15000;

Expected output:

plaintext
Vandana | 10000

BETWEEN is inclusive on both ends. Ivan (15000) was deleted earlier, so only Vandana shows up.


Also Explore These Topics


Want to practice these queries interactively without any setup? W3Schools SQL editor lets you run SQL right in your browser. For the official reference on UPDATE, DELETE, and WHERE syntax used here, see the Oracle SQL documentation.