π― What is Entity?
An Entity is any real-world object, concept, or thing that is uniquely identifiable and about which data can be stored in a database.
Entity: An Entity is a βthingβ or βobjectβ in the real world that is distinguishable from all other objects
It has physical existence. (e.g: Each student in a college is an entity)
Entity can be uniquely identified. (By a primary attribute, aka Primary Key)
π― Example Entities:
In a university database:
π§βπ
Studentπ
Courseπ¨βπ«
Teacher
Each of these is something the database needs to track and store information about.
<div class="infographic-entities">
<style>
.infographic-entities {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--mono-font: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
--display-font: inherit;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
background: var(--paper);
color: var(--ink);
padding: 2rem 1.5rem 2.5rem;
max-width: 760px;
margin: 0 auto;
box-sizing: border-box;
}
.infographic-entities[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
}
.infographic-entities *, .infographic-entities *::before, .infographic-entities *::after {
box-sizing: border-box;
}
.infographic-entities h2 {
font-size: 1.4rem;
margin: 0 0 0.25rem;
letter-spacing: -0.01em;
}
.infographic-entities .subtitle {
color: var(--ink-soft);
font-size: 0.92rem;
margin: 0 0 1.75rem;
max-width: 46ch;
}
.infographic-entities .db-shell {
background: var(--paper-alt);
padding: 1.25rem;
margin-bottom: 1.75rem;
border-radius: 14px;
position: relative;
}
.infographic-entities .db-shell .db-label {
font-size: 0.7rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--ink-soft);
margin-bottom: 0.9rem;
}
.infographic-entities .compare {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
background: transparent;
}
.infographic-entities .compare-col {
background: var(--paper);
padding: 1rem 0.75rem;
cursor: pointer;
border: 1px solid var(--line);
border-top: 3px solid var(--line);
border-radius: 12px;
text-align: center;
transition: background 0.15s, border-color 0.15s;
}
.infographic-entities .compare-col:hover {
background: var(--accent-soft);
}
.infographic-entities .compare-col.is-active {
background: var(--accent-soft);
border-top-color: var(--accent);
animation: entities-pulse 1.6s ease-in-out infinite;
}
@keyframes entities-pulse {
0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); }
50% { box-shadow: 0 0 0 5px var(--accent-soft); }
}
.infographic-entities .compare-col .emoji {
font-size: 1.7rem;
display: block;
margin-bottom: 0.4rem;
transition: transform 0.3s ease;
}
.infographic-entities .compare-col.is-active .emoji {
transform: scale(1.15) translateY(-2px);
}
.infographic-entities .compare-col .name {
font-weight: 600;
font-size: 0.95rem;
}
.infographic-entities .compare-col .tag {
display: block;
font-size: 0.72rem;
color: var(--ink-soft);
margin-top: 0.2rem;
}
@media (max-width: 560px) {
.infographic-entities .compare {
grid-template-columns: 1fr;
}
}
.infographic-entities .record {
margin-top: 1.25rem;
border: 1px solid var(--line);
background: var(--paper);
border-radius: 12px;
overflow: hidden;
}
.infographic-entities .record-head {
background: var(--accent);
color: #fff;
padding: 0.55rem 0.9rem;
font-size: 0.8rem;
font-weight: 600;
display: flex;
align-items: center;
gap: 0.5rem;
}
.infographic-entities .record-body {
display: block;
}
.infographic-entities .field-row {
display: grid;
grid-template-columns: 40% 60%;
border-top: 1px solid var(--line);
font-size: 0.85rem;
}
.infographic-entities .field-row:first-child { border-top: none; }
.infographic-entities .field-key {
padding: 0.55rem 0.9rem;
color: var(--ink-soft);
font-family: var(--mono-font);
font-size: 0.78rem;
background: var(--paper-alt);
}
.infographic-entities .field-val {
padding: 0.55rem 0.9rem;
font-family: var(--mono-font);
font-size: 0.82rem;
opacity: 0;
transform: translateX(-4px);
animation: entities-fade-in 0.35s ease forwards;
}
@keyframes entities-fade-in {
to { opacity: 1; transform: translateX(0); }
}
.infographic-entities .takeaway {
margin-top: 1.5rem;
font-size: 0.88rem;
color: var(--ink-soft);
border-left: 3px solid var(--accent);
padding: 0.5rem 0 0.5rem 0.9rem;
}
.infographic-entities .takeaway strong {
color: var(--ink);
}
.infographic-entities .hint {
font-size: 0.72rem;
color: var(--ink-soft);
text-align: center;
margin-top: 0.6rem;
letter-spacing: 0.02em;
}
.infographic-entities .progress-track {
height: 4px;
background: var(--line);
margin-top: 0.9rem;
border-radius: 999px;
overflow: hidden;
}
.infographic-entities .progress-fill {
height: 100%;
width: 0%;
background: var(--accent);
}
.infographic-entities .progress-fill.is-animating {
animation: entities-progress 3.2s linear forwards;
}
@keyframes entities-progress {
from { width: 0%; }
to { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
.infographic-entities *, .infographic-entities *::before, .infographic-entities *::after {
animation-duration: 0.001ms !important;
transition-duration: 0.001ms !important;
}
}
</style>
<h2>Entities in a Database</h2>
<p class="subtitle">A university database needs to track and store information about several kinds of things. Each one is an <strong>entity</strong>. Click one to see what it actually stores.</p>
<div class="db-shell">
<div class="db-label">University Database</div>
<div class="compare" role="group" aria-label="Entity types">
<button class="compare-col" type="button" data-entity="student">
<span class="emoji">π§βπ</span>
<span class="name">Student</span>
<span class="tag">who is learning</span>
</button>
<button class="compare-col" type="button" data-entity="course">
<span class="emoji">π</span>
<span class="name">Course</span>
<span class="tag">what is taught</span>
</button>
<button class="compare-col" type="button" data-entity="teacher">
<span class="emoji">π¨βπ«</span>
<span class="name">Teacher</span>
<span class="tag">who is teaching</span>
</button>
</div>
<div class="record" id="entities-record">
<div class="record-head" id="entities-record-head">π§βπ Student record</div>
<div class="record-body" id="entities-record-body"></div>
</div>
<div class="progress-track"><div class="progress-fill" id="entities-progress"></div></div>
<div class="hint" id="entities-hint">auto-cycling Β· click any entity to pause & explore</div>
</div>
<p class="takeaway"><strong>Entity = a real thing the database remembers</strong>, and its fields are the specific facts it keeps about that thing.</p>
<script>
(function () {
var wrapper = document.currentScript.closest('.infographic-entities')
|| document.querySelector('.infographic-entities');
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 DATA = {
student: {
head: 'π§βπ Student record',
fields: [
['student_id', 'STU-2041'],
['name', 'Ananya Rao'],
['email', 'ananya.rao@uni.edu'],
['enrolled_in', 'Data Structures, DBMS']
]
},
course: {
head: 'π Course record',
fields: [
['course_id', 'CSE-303'],
['title', 'Database Systems'],
['credits', '4'],
['department', 'Computer Science']
]
},
teacher: {
head: 'π¨βπ« Teacher record',
fields: [
['teacher_id', 'FAC-118'],
['name', 'Dr. Vikram Shah'],
['department', 'Computer Science'],
['teaches', 'CSE-303, CSE-410']
]
}
};
var order = ['student', 'course', 'teacher'];
var cols = wrapper.querySelectorAll('.compare-col');
var head = wrapper.querySelector('#entities-record-head');
var body = wrapper.querySelector('#entities-record-body');
var hint = wrapper.querySelector('#entities-hint');
var progress = wrapper.querySelector('#entities-progress');
var reduceMotion = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var currentIndex = 0;
var autoTimer = null;
var isPaused = false;
function setActiveCol(key) {
cols.forEach(function (c) {
c.classList.toggle('is-active', c.getAttribute('data-entity') === key);
});
}
function render(key) {
var d = DATA[key];
head.textContent = d.head;
body.innerHTML = '';
d.fields.forEach(function (pair, i) {
var row = document.createElement('div');
row.className = 'field-row';
var k = document.createElement('div');
k.className = 'field-key';
k.textContent = pair[0];
var v = document.createElement('div');
v.className = 'field-val';
v.textContent = pair[1];
v.style.animationDelay = (i * 0.06) + 's';
row.appendChild(k);
row.appendChild(v);
body.appendChild(row);
});
}
function restartProgressBar() {
progress.classList.remove('is-animating');
// force reflow so the animation restarts
void progress.offsetWidth;
if (!isPaused) progress.classList.add('is-animating');
}
function showEntity(key) {
setActiveCol(key);
render(key);
restartProgressBar();
}
function advance() {
currentIndex = (currentIndex + 1) % order.length;
showEntity(order[currentIndex]);
}
function startAutoCycle() {
if (reduceMotion) return; // respect reduced-motion: no auto animation
clearInterval(autoTimer);
autoTimer = setInterval(advance, 3200);
progress.classList.add('is-animating');
}
function stopAutoCycle() {
clearInterval(autoTimer);
progress.classList.remove('is-animating');
}
cols.forEach(function (col) {
col.addEventListener('click', function () {
isPaused = true;
stopAutoCycle();
currentIndex = order.indexOf(col.getAttribute('data-entity'));
showEntity(col.getAttribute('data-entity'));
hint.textContent = 'paused Β· showing your selection';
});
});
// initial render, then auto-play with no user action needed
showEntity(order[0]);
if (!reduceMotion) {
startAutoCycle();
hint.textContent = 'auto-cycling Β· click any entity to pause & explore';
} else {
hint.textContent = 'click any entity to explore';
}
})();
</script>
</div>.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!');
});π§© Entity vs Attribute
π§± Term | π‘ Meaning | π Example |
|---|---|---|
Entity | The object or thing being stored |
|
Attribute | Property/characteristic of the entity |
|
𧬠Types of Entities
πΉ Strong Entity
Exists independently
Has its own primary key
π Example:
Student(ID, Name, Age)
πΈ Weak Entity
Cannot exist without a related strong entity
Lacks a primary key on its own
Relies on a foreign key for identification
π Example:
Deparment(Dept_Name, Semester, Student_ID)(Here,
Student_IDis a foreign key from theStudententity)
<div class="infographic-entity-types">
<style>
.infographic-entity-types {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--error: #c0392b;
--error-soft: #fbe9e7;
--success: #2e7d32;
--success-soft: #e8f5e9;
--mono-font: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
background: var(--paper);
color: var(--ink);
padding: 2rem 1.5rem 2.5rem;
max-width: 780px;
margin: 0 auto;
box-sizing: border-box;
}
.infographic-entity-types[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--error: #e57373;
--error-soft: #3a2222;
--success: #66bb6a;
--success-soft: #1b3320;
}
.infographic-entity-types *, .infographic-entity-types *::before, .infographic-entity-types *::after {
box-sizing: border-box;
}
.infographic-entity-types h2 {
font-size: 1.4rem;
margin: 0 0 0.25rem;
letter-spacing: -0.01em;
}
.infographic-entity-types .subtitle {
color: var(--ink-soft);
font-size: 0.92rem;
margin: 0 0 1.5rem;
max-width: 52ch;
}
.infographic-entity-types .stage {
position: relative;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 2.5rem;
align-items: start;
padding-top: 0.5rem;
}
@media (max-width: 600px) {
.infographic-entity-types .stage { grid-template-columns: 1fr; gap: 2.75rem; }
}
.infographic-entity-types .ent-card {
background: var(--paper-alt);
border: 1px solid var(--line);
border-radius: 12px;
padding: 1.1rem 1rem 1.3rem;
position: relative;
transition: opacity 0.4s ease, transform 0.4s ease, filter 0.4s ease;
}
.infographic-entity-types .ent-kicker {
font-size: 0.68rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--accent);
font-weight: 700;
margin-bottom: 0.15rem;
}
.infographic-entity-types .ent-title {
font-weight: 700;
font-size: 1.02rem;
margin-bottom: 0.15rem;
}
.infographic-entity-types .ent-desc {
font-size: 0.78rem;
color: var(--ink-soft);
margin-bottom: 0.75rem;
}
.infographic-entity-types .schema {
background: var(--paper);
border: 1px solid var(--line);
border-radius: 8px;
overflow: hidden;
font-family: var(--mono-font);
font-size: 0.78rem;
}
.infographic-entity-types .schema-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
padding: 0.4rem 0.6rem;
border-top: 1px solid var(--line);
transition: background 0.3s ease, color 0.3s ease;
}
.infographic-entity-types .schema-row:first-child { border-top: none; }
.infographic-entity-types .schema-row .badge {
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
font-size: 0.62rem;
font-weight: 700;
padding: 0.1rem 0.4rem;
border-radius: 999px;
letter-spacing: 0.03em;
white-space: nowrap;
}
.infographic-entity-types .badge.pk {
background: var(--accent-soft);
color: var(--accent);
}
.infographic-entity-types .badge.fk {
background: var(--accent-soft);
color: var(--accent);
}
.infographic-entity-types .schema-row.is-broken {
background: var(--error-soft);
color: var(--error);
}
.infographic-entity-types .schema-row.is-broken .badge {
background: transparent;
color: var(--error);
}
/* link indicator between the two cards */
.infographic-entity-types .link-note {
grid-column: 1 / -1;
text-align: center;
font-size: 0.74rem;
color: var(--ink-soft);
margin-top: -1.6rem;
margin-bottom: 0.4rem;
position: relative;
}
.infographic-entity-types .link-note .chain {
display: inline-block;
transition: opacity 0.3s ease, filter 0.3s ease;
}
@media (max-width: 600px) {
.infographic-entity-types .link-note { display: none; }
}
/* deleted / broken states */
.infographic-entity-types .ent-card.is-deleted {
opacity: 0.35;
filter: grayscale(1);
transform: scale(0.97);
}
.infographic-entity-types .ent-card.is-orphaned {
border-color: var(--error);
}
.infographic-entity-types .ent-card.is-safe {
border-color: var(--success);
}
.infographic-entity-types .status-line {
margin-top: 0.65rem;
font-size: 0.76rem;
font-weight: 600;
min-height: 1.1em;
}
.infographic-entity-types .status-line.ok { color: var(--ink-soft); }
.infographic-entity-types .status-line.error { color: var(--error); }
.infographic-entity-types .status-line.success { color: var(--success); }
.infographic-entity-types .ent-card.shake {
animation: entity-shake 0.4s;
}
@keyframes entity-shake {
0%, 100% { transform: translateX(0); }
20% { transform: translateX(-5px); }
40% { transform: translateX(5px); }
60% { transform: translateX(-4px); }
80% { transform: translateX(3px); }
}
.infographic-entity-types .controls {
display: flex;
justify-content: center;
gap: 0.6rem;
margin-top: 1.6rem;
flex-wrap: wrap;
}
.infographic-entity-types .btn {
font: inherit;
font-size: 0.82rem;
font-weight: 600;
padding: 0.55rem 1rem;
border-radius: 999px;
border: 1px solid var(--line);
background: var(--paper);
color: var(--ink);
cursor: pointer;
transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.2s;
}
.infographic-entity-types .btn:hover:not(:disabled) {
border-color: var(--accent);
color: var(--accent);
}
.infographic-entity-types .btn.primary {
background: var(--error);
border-color: var(--error);
color: #fff;
}
.infographic-entity-types .btn.primary:hover:not(:disabled) {
opacity: 0.9;
color: #fff;
}
.infographic-entity-types .btn:disabled {
opacity: 0.4;
cursor: not-allowed;
}
.infographic-entity-types .takeaway {
margin-top: 1.5rem;
font-size: 0.88rem;
color: var(--ink-soft);
border-left: 3px solid var(--accent);
padding: 0.5rem 0 0.5rem 0.9rem;
transition: border-color 0.3s ease, color 0.3s ease;
}
.infographic-entity-types .takeaway strong { color: var(--ink); }
.infographic-entity-types .takeaway.is-error {
border-left-color: var(--error);
}
@media (prefers-reduced-motion: reduce) {
.infographic-entity-types *, .infographic-entity-types *::before, .infographic-entity-types *::after {
animation-duration: 0.001ms !important;
transition-duration: 0.001ms !important;
}
}
</style>
<h2>Strong vs Weak Entity</h2>
<p class="subtitle">One of these can stand on its own. The other can't. Delete the parent and watch what actually happens.</p>
<div class="stage">
<div class="ent-card" id="ety-strong">
<div class="ent-kicker">πΉ Strong Entity</div>
<div class="ent-title">Student</div>
<div class="ent-desc">Exists independently · has its own primary key</div>
<div class="schema">
<div class="schema-row"><span>ID</span><span class="badge pk">PK</span></div>
<div class="schema-row"><span>Name</span><span></span></div>
<div class="schema-row"><span>Age</span><span></span></div>
</div>
<div class="status-line ok" id="status-strong">alive</div>
</div>
<div class="ent-card" id="ety-weak">
<div class="ent-kicker">πΈ Weak Entity</div>
<div class="ent-title">Department</div>
<div class="ent-desc">No primary key of its own · identified through Student</div>
<div class="schema">
<div class="schema-row"><span>Dept_Name</span><span></span></div>
<div class="schema-row"><span>Semester</span><span></span></div>
<div class="schema-row" id="row-fk"><span>Student_ID</span><span class="badge fk">FK</span></div>
</div>
<div class="status-line ok" id="status-weak">alive · linked to Student.ID</div>
</div>
<div class="link-note"><span class="chain" id="chain-note">π Student_ID references Student.ID</span></div>
</div>
<div class="controls">
<button class="btn primary" id="btn-delete-student" type="button">ποΈ Delete Student</button>
<button class="btn" id="btn-delete-dependent" type="button">ποΈ Delete Department</button>
<button class="btn" id="btn-reset" type="button" disabled>βΊ Reset</button>
</div>
<p class="takeaway" id="ety-takeaway"><strong>Weak entities borrow their identity</strong> from a strong entity β remove the parent, and the dependent has nothing left to point to.</p>
<script>
(function () {
var wrapper = document.currentScript.closest('.infographic-entity-types')
|| document.querySelector('.infographic-entity-types');
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 strongCard = wrapper.querySelector('#ety-strong');
var weakCard = wrapper.querySelector('#ety-weak');
var statusStrong = wrapper.querySelector('#status-strong');
var statusWeak = wrapper.querySelector('#status-weak');
var rowFk = wrapper.querySelector('#row-fk');
var chainNote = wrapper.querySelector('#chain-note');
var takeaway = wrapper.querySelector('#ety-takeaway');
var btnDeleteStudent = wrapper.querySelector('#btn-delete-student');
var btnDeleteDependent = wrapper.querySelector('#btn-delete-dependent');
var btnReset = wrapper.querySelector('#btn-reset');
function shake(el) {
el.classList.remove('shake');
void el.offsetWidth;
el.classList.add('shake');
}
function deleteStudent() {
strongCard.classList.add('is-deleted');
statusStrong.textContent = 'deleted';
statusStrong.className = 'status-line error';
chainNote.style.opacity = '0.25';
chainNote.style.filter = 'grayscale(1)';
btnDeleteStudent.disabled = true;
btnDeleteDependent.disabled = true;
btnReset.disabled = false;
setTimeout(function () {
shake(weakCard);
weakCard.classList.add('is-orphaned');
rowFk.classList.add('is-broken');
statusWeak.textContent = 'π orphaned β Student_ID matches nothing';
statusWeak.className = 'status-line error';
takeaway.classList.add('is-error');
takeaway.innerHTML = '<strong>Department just broke.</strong> With no Student to reference, its foreign key is meaningless β a weak entity cannot survive on its own.';
}, 550);
}
function deleteDependentOnly() {
shake(weakCard);
weakCard.classList.add('is-deleted');
statusWeak.textContent = 'deleted';
statusWeak.className = 'status-line error';
btnDeleteStudent.disabled = true;
btnDeleteDependent.disabled = true;
btnReset.disabled = false;
statusStrong.textContent = 'π alive Β· unaffected';
statusStrong.className = 'status-line success';
strongCard.classList.add('is-safe');
takeaway.classList.remove('is-error');
takeaway.innerHTML = '<strong>Student is untouched.</strong> A strong entity never depends on a weak one β the relationship only runs one way.';
}
function reset() {
strongCard.classList.remove('is-deleted', 'is-safe');
weakCard.classList.remove('is-deleted', 'is-orphaned');
rowFk.classList.remove('is-broken');
chainNote.style.opacity = '';
chainNote.style.filter = '';
statusStrong.textContent = 'alive';
statusStrong.className = 'status-line ok';
statusWeak.textContent = 'alive Β· linked to Student.ID';
statusWeak.className = 'status-line ok';
takeaway.classList.remove('is-error');
takeaway.innerHTML = '<strong>Weak entities borrow their identity</strong> from a strong entity β remove the parent, and the dependent has nothing left to point to.';
btnDeleteStudent.disabled = false;
btnDeleteDependent.disabled = false;
btnReset.disabled = true;
}
btnDeleteStudent.addEventListener('click', deleteStudent);
btnDeleteDependent.addEventListener('click', deleteDependentOnly);
btnReset.addEventListener('click', reset);
})();
</script>
</div>.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
π€ Concept | π Description |
|---|---|
Entity | Real-world object to store data about |
Attribute | Describes a property of an entity |
Entity Set | Collection of entities of the same type |
Strong Entity | Independent, has a primary key |
Weak Entity | Depends on another entity, no independent key |