DML is a category of SQL used to modify the data inside existing tables.
It allows you to add, update, and delete records.
⚙️ Base Setup (ONE Code Block)
We will use THIS data for all examples below ⬇️
-- Base Table
CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
grade VARCHAR(2)
);📌 We will use ONLY this table and data for all examples below
No repeated CREATE TABLE or INSERT again.
➕ INSERT – Add New Records
Used to insert new rows into a table.
📌 Basic Example:
INSERT INTO students (name, grade)
VALUES ('Swastika', 'A');📌 Insert multiple rows:
INSERT INTO students (name, grade)
VALUES
('Anya','B'),
('Riya','A');✏️ UPDATE – Modify Existing Records
Used to change data in one or more rows.
📌 Update one row:
UPDATE students
SET grade = 'A+'
WHERE id = 1;📌 Update all rows:
UPDATE students
SET grade = 'B';⚠️ Be careful — without WHERE, it updates every row
🗑️ DELETE – Remove Records
Used to delete rows from a table.
📌 Delete one row:
DELETE FROM students
WHERE id = 1;📌 Delete all rows (but keep structure):
DELETE FROM students;⚠️ Use TRUNCATE (from DDL) if you want faster full-table deletion
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>INSERT, UPDATE, DELETE — Try It Yourself</title>
<style>
.infographic-dmlrunner {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--good: #16a34a;
--good-soft: #dcfce7;
--bad: #dc2626;
--bad-soft: #fee2e2;
--warn: #b45309;
--warn-soft: #fef3c7;
--on-accent: #ffffff;
--display-font: Georgia, 'Iowan Old Style', serif;
--body-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
--mono-font: 'SF Mono', Consolas, monospace;
background: var(--paper);
color: var(--ink);
font-family: var(--body-font);
max-width: 780px;
margin: 0 auto;
box-sizing: border-box;
overflow-x: hidden;
}
.infographic-dmlrunner[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--good: #4ade80;
--good-soft: #123420;
--bad: #f87171;
--bad-soft: #3a1414;
--warn: #fbbf24;
--warn-soft: #3a2f0e;
--on-accent: #101418;
}
.infographic-dmlrunner * { box-sizing: border-box; }
.dm-topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; gap: 0.5rem; flex-wrap: wrap; }
.dm-progress { font-size: 0.78rem; color: var(--ink-soft); }
.dm-showfull-btn {
font: inherit; font-size: 0.78rem; background: none; border: 1px solid var(--line);
border-radius: 999px; padding: 0.35rem 0.8rem; cursor: pointer; color: var(--ink-soft);
}
.dm-showfull-btn:hover { border-color: var(--accent); color: var(--accent); }
.dm-showfull-btn.is-on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dm-fullcode-panel { display: none; margin-bottom: 1.25rem; }
.dm-fullcode-panel.is-visible { display: block; }
.dm-fullcode-scroll { overflow-x: auto; }
.dm-fullcode {
background: var(--ink); color: #d4e2ff; border-radius: 8px; padding: 1rem 1.2rem;
font-family: var(--mono-font); font-size: 0.72rem; line-height: 1.7; white-space: pre; opacity: 0.85;
display: inline-block;
min-width: 100%;
}
.infographic-dmlrunner[data-theme="dark"] .dm-fullcode { background: #05070a; }
.dm-frame { background: var(--paper-alt); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem; }
.dm-kw { color: #9cc5ff; } .dm-str { color: #f8d980; } .dm-num { color: #4ade80; } .dm-cm { color: #7c8aa8; }
.dm-step { display: none; margin-bottom: 1rem; }
.dm-step.is-revealed { display: block; animation: dm-step-in 0.4s ease; }
@keyframes dm-step-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.dm-step.is-done .dm-step-code-full { display: none; }
.dm-step.is-done .dm-step-done-pill { display: flex; }
.dm-step-done-pill {
display: none; align-items: center; gap: 0.5rem; background: var(--good-soft); color: var(--good);
border-radius: 7px; padding: 0.55rem 0.85rem; font-family: var(--mono-font); font-size: 0.78rem; cursor: pointer;
}
.dm-step-done-pill.is-danger-done { background: var(--bad-soft); color: var(--bad); }
.dm-step-done-pill .chevron { margin-left: auto; font-size: 0.7rem; opacity: 0.7; }
.dm-step.is-expanded-done .dm-step-code-full { display: block; }
.dm-step.is-expanded-done .dm-step-done-pill { background: var(--accent-soft); color: var(--accent); }
.dm-step-label { font-family: var(--display-font); font-size: 1.02rem; margin: 0 0 0.5rem; }
.dm-step-desc { font-size: 0.82rem; color: var(--ink-soft); margin: 0 0 0.7rem; line-height: 1.45; }
.dm-step-warn {
font-size: 0.8rem; color: var(--warn); background: var(--warn-soft); border-radius: 7px;
padding: 0.5rem 0.7rem; margin: 0 0 0.7rem; line-height: 1.4;
}
.dm-code-scroll { overflow-x: auto; }
.dm-code {
background: var(--ink); color: #d4e2ff; border-radius: 8px; padding: 0.85rem 1.05rem;
font-family: var(--mono-font); font-size: 0.8rem; line-height: 1.6; white-space: pre;
display: inline-block;
min-width: 100%;
}
.infographic-dmlrunner[data-theme="dark"] .dm-code { background: #05070a; }
.dm-run-row { display: flex; justify-content: center; gap: 0.5rem; margin-top: 0.85rem; flex-wrap: wrap; }
.dm-run-btn {
font: inherit; font-size: 0.83rem; background: var(--accent); color: var(--on-accent);
border: none; border-radius: 7px; padding: 0.55rem 1rem; cursor: pointer;
}
.dm-run-btn:hover { opacity: 0.9; }
.dm-run-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.dm-run-btn.is-danger { background: var(--bad); }
.dm-run-btn.is-secondary { background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.dm-run-btn.dm-next-btn { background: var(--good); display: none; }
.dm-mini-msg {
margin-top: 0.7rem; padding: 0.55rem 0.75rem; border-radius: 7px; font-size: 0.8rem; line-height: 1.5; display: none;
}
.dm-mini-msg.is-visible { display: block; }
.dm-mini-msg.st-good { background: var(--good-soft); color: var(--good); }
.dm-mini-msg.st-bad { background: var(--bad-soft); color: var(--bad); }
.dm-mini-msg.st-warn { background: var(--warn-soft); color: var(--warn); }
.dm-output-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); margin: 1.1rem 0 0.6rem; }
.dm-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; min-width: 0; }
table.dm-table {
width: 100%; min-width: 260px; border-collapse: collapse; background: var(--paper);
border-radius: 8px; font-size: 0.88rem;
}
table.dm-table th, table.dm-table td {
border: 1px solid var(--line); padding: 0.5rem 0.7rem; text-align: left; white-space: nowrap;
transition: background 0.3s, color 0.3s;
}
table.dm-table th { background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 0.75rem; }
table.dm-table tr.is-new td { animation: dm-row-in 0.9s ease; }
@keyframes dm-row-in { 0%,35% { background: var(--good-soft); } 100% { background: transparent; } }
table.dm-table td.is-changed { animation: dm-row-in 0.9s ease; color: var(--accent); font-weight: 700; }
table.dm-table tr.is-removing td { opacity: 0.3; text-decoration: line-through; background: var(--bad-soft); }
.dm-empty-note { font-size: 0.82rem; color: var(--ink-soft); font-style: italic; padding: 0.5rem 0.2rem; }
.dm-reset-row { display: flex; justify-content: center; margin-top: 1.25rem; }
@media (prefers-reduced-motion: reduce) {
.infographic-dmlrunner *, .infographic-dmlrunner *::before, .infographic-dmlrunner *::after {
transition-duration: 0.001ms !important; animation-duration: 0.001ms !important;
}
}
</style>
</head>
<body>
<div class="infographic-dmlrunner" id="dmlrunner">
<div class="dm-topbar">
<span class="dm-progress" id="dmProgress"></span>
<button class="dm-showfull-btn" id="dmShowFullBtn" type="button">👁️ Show full SQL script</button>
</div>
<div class="dm-fullcode-panel" id="dmFullCodePanel">
<div class="dm-fullcode-scroll">
<div class="dm-fullcode" id="dmFullCodeContent"></div>
</div>
</div>
<div class="dm-frame">
<div id="dmSteps"></div>
<p class="dm-output-label">Table: students</p>
<div class="dm-table-scroll">
<table class="dm-table" id="dmTable">
<thead><tr><th>id</th><th>name</th><th>grade</th></tr></thead>
<tbody id="dmTbody"></tbody>
</table>
</div>
<p class="dm-empty-note" id="dmEmptyNote" style="display:none;">(no rows)</p>
<div class="dm-reset-row">
<button class="dm-run-btn is-secondary" id="dmReset" type="button">↺ Reset all</button>
</div>
</div>
</div>
<script>
(function () {
const wrapper = document.getElementById('dmlrunner');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
})();
(function () {
function kw(s) { return '<span class="dm-kw">' + s + '</span>'; }
function str(s) { return '<span class="dm-str">' + s + '</span>'; }
function cm(s) { return '<span class="dm-cm">' + s + '</span>'; }
const setupCode =
cm('-- Base Table') + '\n' +
kw('CREATE TABLE') + ' students (\n' +
' id ' + kw('INT AUTO_INCREMENT PRIMARY KEY') + ',\n' +
' name ' + kw('VARCHAR') + '(50),\n' +
' grade ' + kw('VARCHAR') + '(2)\n' +
');';
const insertOneCode = kw('INSERT INTO') + ' students (name, grade)\n' + kw('VALUES') + ' (' + str("'Swastika'") + ', ' + str("'A'") + ');';
const insertManyCode = kw('INSERT INTO') + ' students (name, grade)\n' + kw('VALUES') + '\n (' + str("'Anya'") + ',' + str("'B'") + '),\n (' + str("'Riya'") + ',' + str("'A'") + ');';
const updateOneCode = kw('UPDATE') + ' students\n' + kw('SET') + ' grade = ' + str("'A+'") + '\n' + kw('WHERE') + ' id = 1;';
const updateAllCode = kw('UPDATE') + ' students\n' + kw('SET') + ' grade = ' + str("'B'") + ';';
const deleteOneCode = kw('DELETE FROM') + ' students\n' + kw('WHERE') + ' id = 1;';
const deleteAllCode = kw('DELETE FROM') + ' students;';
const table = document.getElementById('dmTable');
const tbody = document.getElementById('dmTbody');
const emptyNote = document.getElementById('dmEmptyNote');
const stepsContainer = document.getElementById('dmSteps');
const progress = document.getElementById('dmProgress');
const fullCodeContent = document.getElementById('dmFullCodeContent');
let nextId = 1;
function refreshEmptyNote() {
emptyNote.style.display = tbody.children.length === 0 ? 'block' : 'none';
}
function insertRow(name, grade) {
const tr = document.createElement('tr');
tr.className = 'is-new';
tr.dataset.id = nextId;
tr.innerHTML = '<td>' + nextId + '</td><td>' + name + '</td><td>' + grade + '</td>';
tbody.appendChild(tr);
nextId++;
refreshEmptyNote();
}
const steps = [
{ key: 'setup', title: '⚙️ Base Setup', desc: 'Just the table this time — no data yet.', code: setupCode, type: 'setup' },
{ key: 'insertOne', title: '➕ INSERT — one row', desc: 'Adds a single new record.', code: insertOneCode, type: 'insertOne' },
{ key: 'insertMany', title: '➕ INSERT — multiple rows', desc: 'One statement, several rows at once.', code: insertManyCode, type: 'insertMany' },
{ key: 'updateOne', title: '✏️ UPDATE — one row', desc: 'Changes data in a single, targeted row.', code: updateOneCode, type: 'updateOne' },
{ key: 'updateAll', title: '✏️ UPDATE — all rows', desc: '', code: updateAllCode, type: 'updateAll',
warn: '⚠️ No WHERE clause — this updates every single row in the table.' },
{ key: 'deleteOne', title: '🗑️ DELETE — one row', desc: 'Removes a single, targeted row.', code: deleteOneCode, type: 'deleteOne' },
{ key: 'deleteAll', title: '🗑️ DELETE — all rows', desc: '', code: deleteAllCode, type: 'deleteAll',
warn: '⚠️ No WHERE clause — every remaining row is deleted, though the table structure itself stays. (TRUNCATE, from DDL, does this faster.)' }
];
fullCodeContent.innerHTML = steps.map(s => s.code).join('\n\n');
steps.forEach((s, i) => {
const stepEl = document.createElement('div');
stepEl.className = 'dm-step' + (i === 0 ? ' is-revealed' : '');
stepEl.id = 'step-' + s.key;
const label = s.type === 'setup' ? 'Setup' : ('Run ' + s.title.replace(/^[^\s]+\s/, ''));
stepEl.innerHTML =
'<div class="dm-step-done-pill' + (s.warn ? ' is-danger-done' : '') + '"><span>✓ ' + s.title + '</span><span class="chevron">\u25be view code</span></div>' +
'<div class="dm-step-code-full">' +
'<p class="dm-step-label">' + s.title + '</p>' +
(s.desc ? '<p class="dm-step-desc">' + s.desc + '</p>' : '') +
(s.warn ? '<p class="dm-step-warn">' + s.warn + '</p>' : '') +
'<div class="dm-code-scroll"><div class="dm-code">' + s.code + '</div></div>' +
'<div class="dm-run-row"><button class="dm-run-btn' + (s.warn ? ' is-danger' : '') + '" id="btn-' + s.key + '" type="button">▶ ' + label + '</button></div>' +
'<p class="dm-mini-msg" id="msg-' + s.key + '"></p>' +
(i < steps.length - 1 ? '<div class="dm-run-row"><button class="dm-run-btn dm-next-btn" id="nextstep-' + s.key + '" type="button">Next operation →</button></div>' : '') +
'</div>';
stepsContainer.appendChild(stepEl);
});
function updateProgress(doneCount) {
progress.textContent = doneCount + ' / ' + steps.length + ' operations run';
}
updateProgress(0);
function showMsg(key, text, kind) {
const el = document.getElementById('msg-' + key);
el.textContent = text;
el.className = 'dm-mini-msg is-visible st-' + kind;
}
function unlockNext(key) {
const btn = document.getElementById('nextstep-' + key);
if (btn) btn.style.display = 'inline-block';
}
let doneCount = 0;
function goToNext(key) {
document.getElementById('step-' + key).classList.add('is-done');
doneCount++;
updateProgress(doneCount);
const idx = steps.findIndex(s => s.key === key);
const next = steps[idx + 1];
if (next) {
const nextEl = document.getElementById('step-' + next.key);
nextEl.classList.add('is-revealed');
nextEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
}
refreshEmptyNote();
steps.forEach(s => {
document.getElementById('btn-' + s.key).addEventListener('click', () => {
document.getElementById('btn-' + s.key).disabled = true;
if (s.type === 'setup') {
showMsg(s.key, 'Table created — empty, ready for data.', 'good');
} else if (s.type === 'insertOne') {
insertRow('Swastika', 'A');
showMsg(s.key, '1 row inserted.', 'good');
} else if (s.type === 'insertMany') {
insertRow('Anya', 'B');
insertRow('Riya', 'A');
showMsg(s.key, '2 rows inserted in one statement.', 'good');
} else if (s.type === 'updateOne') {
const row = tbody.querySelector('tr[data-id="1"]');
if (row) {
const cell = row.children[2];
cell.textContent = 'A+';
cell.classList.add('is-changed');
}
showMsg(s.key, "1 row updated — Swastika's grade is now A+.", 'good');
} else if (s.type === 'updateAll') {
const rows = tbody.querySelectorAll('tr');
rows.forEach(row => {
const cell = row.children[2];
cell.textContent = 'B';
cell.classList.add('is-changed');
});
showMsg(s.key, rows.length + ' row(s) updated — every row now has grade B, whether that was intended or not.', 'warn');
} else if (s.type === 'deleteOne') {
const row = tbody.querySelector('tr[data-id="1"]');
if (row) {
row.classList.add('is-removing');
setTimeout(() => { row.remove(); refreshEmptyNote(); }, 500);
}
showMsg(s.key, '1 row deleted.', 'bad');
} else if (s.type === 'deleteAll') {
const rows = tbody.querySelectorAll('tr');
rows.forEach(row => row.classList.add('is-removing'));
setTimeout(() => { tbody.innerHTML = ''; refreshEmptyNote(); }, 500);
showMsg(s.key, rows.length + ' row(s) deleted — table is now empty, but it still exists with its columns intact.', 'warn');
}
unlockNext(s.key);
});
const nextBtn = document.getElementById('nextstep-' + s.key);
if (nextBtn) nextBtn.addEventListener('click', () => goToNext(s.key));
});
document.getElementById('dmShowFullBtn').addEventListener('click', function () {
const panel = document.getElementById('dmFullCodePanel');
const on = panel.classList.toggle('is-visible');
this.classList.toggle('is-on', on);
this.textContent = on ? '👁️ Hide full SQL script' : '👁️ Show full SQL script';
});
document.querySelectorAll('.dm-step-done-pill').forEach(pill => {
pill.addEventListener('click', () => {
const step = pill.closest('.dm-step');
step.classList.toggle('is-expanded-done');
pill.querySelector('.chevron').textContent = step.classList.contains('is-expanded-done') ? '\u25b4 hide code' : '\u25be view code';
});
});
document.getElementById('dmReset').addEventListener('click', () => {
doneCount = 0;
nextId = 1;
updateProgress(0);
tbody.innerHTML = '';
refreshEmptyNote();
steps.forEach((s, i) => {
const el = document.getElementById('step-' + s.key);
el.classList.remove('is-done', 'is-expanded-done');
el.classList.toggle('is-revealed', i === 0);
document.getElementById('msg-' + s.key).classList.remove('is-visible');
document.getElementById('btn-' + s.key).disabled = false;
const nextBtn = document.getElementById('nextstep-' + s.key);
if (nextBtn) nextBtn.style.display = 'none';
});
});
})();
</script>
</body>
</html>.demo {
font-family: system-ui, sans-serif;
padding: 16px;
}
.demo h1 {
color: #2563eb;
margin: 0 0 8px;
}
.demo p {
color: #4b5563;
margin: 0;
}document.querySelector('.demo h1')?.addEventListener('click', () => {
alert('Hello from live preview!');
});✅ Summary Table
DML Command | Purpose | Example |
|---|---|---|
➕ | Add new rows |
|
✏️ | Modify existing rows |
|
🗑️ | Remove rows from table |
|