๐๏ธ Database Instance
A Database Instance refers to the current state of the database at a particular moment in time โ including the data that is actually stored in the database right now.
๐ง Understanding the Term Simply:
The database schema defines the structure: tables, columns, data types, etc.
The instance is the actual data filled in those tables at a specific time.
๐ Example:
Let's say we have this schema:
CREATE TABLE Student (
RollNo INT,
Name VARCHAR(50),
Marks INT
);Thatโs the schema โ it describes the structure.
Now, suppose this data is currently in the table:
Roll No | Name | Marks |
|---|---|---|
101 | Aditi | 88 |
102 | Rahul | 92 |
This actual content is the instance of the Student table.
<div class="infographic-schinst" id="schinstWrap">
<style>
.infographic-schinst {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f6f3ee;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--success: #1a8a5f;
--success-soft: #e1f5ec;
background: var(--paper);
color: var(--ink);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
padding: 2.5rem 1.5rem;
border-radius: 14px;
box-sizing: border-box;
max-width: 620px;
margin: 0 auto;
}
.infographic-schinst[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--success: #4fd8a8;
--success-soft: #123528;
}
.infographic-schinst * { box-sizing: border-box; }
.si-eyebrow {
font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase;
color: var(--accent); font-weight: 700; margin: 0 0 0.4rem; text-align: center;
}
.si-title { font-size: 1.4rem; font-weight: 700; margin: 0 0 0.5rem; text-align: center; letter-spacing: -0.01em; }
.si-sub { font-size: 0.86rem; color: var(--ink-soft); text-align: center; margin: 0 0 1.75rem; }
.si-card {
border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem 1.2rem; margin-bottom: 1rem;
}
.si-card.schema-card { background: var(--paper-alt); }
.si-card.instance-card { background: var(--paper); border-width: 2px; transition: border-color .3s; }
.si-card.instance-card.is-pulsing { border-color: var(--success); }
.si-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.si-card-title { font-size: 0.95rem; font-weight: 700; }
.si-card-tag {
font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700;
padding: 0.2rem 0.55rem; border-radius: 999px;
}
.si-card-tag.fixed { background: var(--accent-soft); color: var(--accent); }
.si-card-tag.version { background: var(--success-soft); color: var(--success); transition: background .3s, color .3s; }
.si-schema-cols { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.si-col-chip {
background: var(--paper); border: 1px solid var(--line); border-radius: 6px;
padding: 0.4rem 0.65rem; font-size: 0.8rem;
}
.si-col-chip .col-type { color: var(--ink-soft); font-size: 0.68rem; }
.si-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.si-table th, .si-table td {
padding: 0.5rem 0.65rem; text-align: left; border-bottom: 1px solid var(--line);
}
.si-table th {
color: var(--ink-soft); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em;
}
.si-table tr:last-child td { border-bottom: none; }
.si-row-new { animation: siRowIn .5s ease; }
@keyframes siRowIn {
from { opacity: 0; transform: translateY(-6px); background: var(--success-soft); }
to { opacity: 1; transform: translateY(0); }
}
.si-controls { display: flex; justify-content: center; margin-top: 1.5rem; }
.si-btn {
font: inherit; font-weight: 600; font-size: 0.88rem;
background: var(--accent); color: var(--paper);
border: none; border-radius: 8px; padding: 0.65rem 1.3rem; cursor: pointer;
transition: opacity .15s, background .2s;
}
.infographic-schinst[data-theme="dark"] .si-btn { color: #0c0c0c; }
.si-btn:hover { opacity: 0.88; }
.si-btn.is-reset { background: var(--ink-soft); }
.si-note {
text-align: center; font-size: 0.8rem; color: var(--ink-soft); margin-top: 0.9rem;
min-height: 1.2rem;
}
.si-note.is-fading { animation: siNoteFade .4s ease; }
@keyframes siNoteFade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
.infographic-schinst *, .infographic-schinst *::before, .infographic-schinst *::after {
animation-duration: 0.001ms !important; transition-duration: 0.001ms !important;
}
}
</style>
<p class="si-eyebrow">Schema vs. Instance</p>
<h2 class="si-title">The Instance Can Change โ the Schema Can't</h2>
<p class="si-sub">Add a record and watch which one actually moves.</p>
<div class="si-card schema-card">
<div class="si-card-head">
<span class="si-card-title">Schema</span>
<span class="si-card-tag fixed">Never changes</span>
</div>
<div class="si-schema-cols">
<span class="si-col-chip">RollNo <span class="col-type">INT</span></span>
<span class="si-col-chip">Name <span class="col-type">VARCHAR(50)</span></span>
<span class="si-col-chip">Marks <span class="col-type">INT</span></span>
</div>
</div>
<div class="si-card instance-card" id="instanceCard">
<div class="si-card-head">
<span class="si-card-title">Instance</span>
<span class="si-card-tag version" id="versionTag">v1</span>
</div>
<table class="si-table">
<thead>
<tr><th>RollNo</th><th>Name</th><th>Marks</th></tr>
</thead>
<tbody id="instanceRows"></tbody>
</table>
</div>
<div class="si-controls">
<button class="si-btn" id="siActionBtn" type="button">โ Insert new student (103, Meena, 95)</button>
</div>
<p class="si-note" id="siNote">This is Instance v1 of the Student table.</p>
</div>
<script>
(function () {
var wrapper = document.getElementById('schinstWrap');
// Dark mode detection โ body attribute wins, then cookie, then light default
var bodyAttr = document.body.getAttribute('data-darkmode');
var dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
var match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
var baseRows = [
[101, 'Aditi', 88],
[102, 'Rahul', 92]
];
var newRow = [103, 'Meena', 95];
var rowsBody = document.getElementById('instanceRows');
var versionTag = document.getElementById('versionTag');
var instanceCard = document.getElementById('instanceCard');
var actionBtn = document.getElementById('siActionBtn');
var note = document.getElementById('siNote');
var inserted = false;
function renderRows(includeNew, animateNew) {
rowsBody.innerHTML = '';
baseRows.forEach(function (r) {
var tr = document.createElement('tr');
tr.innerHTML = '<td>' + r[0] + '</td><td>' + r[1] + '</td><td>' + r[2] + '</td>';
rowsBody.appendChild(tr);
});
if (includeNew) {
var tr = document.createElement('tr');
if (animateNew) tr.className = 'si-row-new';
tr.innerHTML = '<td>' + newRow[0] + '</td><td>' + newRow[1] + '</td><td>' + newRow[2] + '</td>';
rowsBody.appendChild(tr);
}
}
function setNote(text) {
note.textContent = text;
note.classList.remove('is-fading');
void note.offsetWidth;
note.classList.add('is-fading');
}
function pulseCard() {
instanceCard.classList.add('is-pulsing');
setTimeout(function () { instanceCard.classList.remove('is-pulsing'); }, 900);
}
actionBtn.addEventListener('click', function () {
if (!inserted) {
inserted = true;
renderRows(true, true);
versionTag.textContent = 'v2';
pulseCard();
setNote('A new instance โ same schema, one more row of data.');
actionBtn.textContent = 'โบ Reset to Instance v1';
actionBtn.classList.add('is-reset');
} else {
inserted = false;
renderRows(false, false);
versionTag.textContent = 'v1';
setNote('This is Instance v1 of the Student table.');
actionBtn.textContent = 'โ Insert new student (103, Meena, 95)';
actionBtn.classList.remove('is-reset');
}
});
renderRows(false, false);
})();
</script>.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!');
});๐ Schema vs Instance Summary:
Feature | Schema | Instance |
|---|---|---|
Definition | Structure of the database | Actual data in the database |
Changes | Rarely changes | Changes frequently |
Lifespan | Static over long term | Dynamic (changes with operations) |
Example | Table definitions | Rows inside tables |