📘 CodingMarble Learn

Database Concepts: DBMS, Relations and Keys

Keeping data in separate files causes duplication, inconsistency and poor security. A database stores related data in one organised place, and a DBMS (like MySQL) is the software that manages it. In the relational model, data is kept in tables (relations) made of columns (attributes) and rows (tuples); a domain is the set of allowed values of a column. A candidate key uniquely identifies each row; one is chosen as the primary key and the others are alternate keys.

🎬 Step-by-step story

  1. Separate files repeat data and get out of step. A database keeps one copy.
  2. A DBMS sits between users and data and manages everything.
  3. A table is a relation: columns are attributes, rows are tuples.
  4. A domain is the set of values a column is allowed to take.
  5. Candidate keys identify each row. One becomes the primary key; the rest are alternate keys.
  6. Your turn: test each column to see if it can be a key.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Isn't a spreadsheet already a database?

A spreadsheet can hold a table, but a DBMS adds sharing by many users at once, rules (keys, domains), security and powerful queries.

Why are rows called tuples?

In maths, an ordered set of values is a tuple. Each row is an ordered set of values, one for each attribute.

Who decides the domain?

The database designer, based on real rules (class 9–12, marks 0–100). The DBMS then rejects values outside it.

If both AdmNo and Email are unique, why choose AdmNo?

It is short, never changes and every student has one. Emails can change or be missing.

Can a key be made of two columns?

Yes. When no single column is unique, a set like (Class, RollNo) can be the key. This is a composite key.

Why do we need a database?

In a file system, each department keeps its own files. This causes problems:

A database is an organised collection of related data stored in one place, so it can be shared, kept consistent and protected.

Database Management System (DBMS)

A DBMS is software to create, store, update, search and manage a database, and to control who can use it. Examples: MySQL, Oracle, PostgreSQL, SQLite, Microsoft Access.

Advantages: less redundancy, consistency, sharing by many users, security with passwords and permissions, backup and recovery, and easy searching with a query language (SQL).

Everyday uses: banking, railway reservation, school records, online shopping, hospitals.

Relational model: relation, attribute, tuple, domain

In the relational data model, data is kept in tables.

Rules: each column has a unique name; the order of rows or columns does not matter; no two rows are exactly the same; each cell holds one single value (or NULL, meaning unknown).

Keys: candidate, primary and alternate

Example: STUDENT(AdmNo, Name, Class, Email). Name repeats, Class repeats, so they are not keys. AdmNo and (if always filled and different) Email are candidate keys. Choose AdmNo as primary key; Email becomes the alternate key.

Also useful: a composite key uses two or more columns together (like Class + RollNo); a foreign key is a column in one table that refers to the primary key of another table, linking the two.

Try it: find the key in your ID card

Look at your school ID card or a bus pass. List every field (name, class, roll no, admission no, phone). For each, ask two questions: can two students have the same value? Can it be empty? Write which are candidate keys and which you would pick as primary key. Then test the same idea in step 6 of the 3D.

Key formulas and definitions

Worked examples

1. A table has 5 columns and 30 rows. Give its degree and cardinality.

Degree = 5, cardinality = 30.

2. After adding 2 rows and 1 column to a 4 × 10 (degree 4, cardinality 10) table, what are the new values?

Degree = 5, cardinality = 12.

3. EMPLOYEE(EmpID, Name, Aadhaar, Dept). Identify candidate, primary and alternate keys.

EmpID and Aadhaar are unique → candidate keys. Choose EmpID as primary key; Aadhaar is the alternate key. Name and Dept can repeat.

4. Why can't Name be a primary key in STUDENT?

Two students can have the same name, so it does not identify a row uniquely.

5. Give the domain of an attribute Gender stored as one letter.

{"M", "F", "O"} (or whatever codes the school allows).

Common mistakes

Practice quiz

1. A row in a relation is called a:
2. The number of columns in a relation is its:
3. A candidate key not chosen as primary key is a/an:
4. Which is a DBMS?
5. Same data stored in many files is called:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is the need for a database?

To avoid duplicate and inconsistent data in separate files, and to share, secure and search data easily.

What is the difference between candidate, primary and alternate keys?

Candidate keys can each identify rows uniquely; the one chosen is the primary key; the others are alternate keys.

What are degree and cardinality?

Degree is the number of columns (attributes); cardinality is the number of rows (tuples) in a relation.

Where this is taught

ItalySecondaria di secondo grado – classe 3ªTools and foundations
ItalySecondaria di secondo grado – classe 4ªTools and foundations
NetherlandsHAVO 5 (eindexamenjaar)Elective theme: Databases
NetherlandsVWO 6 (eindexamenjaar)Elective theme: Databases
PolandLiceum ogólnokształcące, klasa IIProgramming and solving problems with computers
RomaniaClasa a X-aDatabases
RomaniaClasa a XII-aModule 1: Databases (compulsory)
RomaniaClasa a XII-aModule 2: Database management systems (optional)
RomaniaClasa a XII-aModern user skills
RomaniaClasa a XII-aWorking with a database application
Ukraine9 класInformation systems and data management
Ukraine10 класBase module: database systems
CBSE (India)Class 11Database Concepts and SQL
CBSE (India)Class 11RDBMS
England (GCSE, A level)Year 113.7 Relational databases and SQL
Japan高校1年Networks and data
Japan高校(専門学科)1〜3年Using Software
Japan高校(専門学科)1〜3年Computer Systems Technology
Japan高校(専門学科)1〜3年Databases
South Korea고등학교 2학년Understanding data science
South Korea고등학교 3학년Data and information
Germany (Bavaria)Jahrgangsstufe 10Data modelling and relational databases
FranceSecondeThemes
FrancePremièreTabular data
FranceTerminaleSpecific option — management information systems
Russia9 классTheoretical foundations
Russia11 классInformation technologies

Learn first

Learn next

Related lessons

All Informatics Practices lessons