Vista Academy ยท SQL Data Analytics ยท Lesson 2

Databases, Tables and Keys

Learn how relational data is organized, how primary and foreign keys identify and connect records, and how to model a customer-order relationship.

Progress0%

0 of 8 concepts passed

Concept 1 of 8

A Database Is a Collection of Tables

A database stores related information in an organized way. A customer database might contain Customers, Orders and Products tables, each holding a different kind of information.

  • A database can contain multiple tables.
  • Each table represents a subject or entity.
  • Tables can be connected through related columns.

Step 1 ยท Interactive teaching lab

A Database Is a Collection of Tables

Explore ยท click ยท compare

Select a table to inspect the type of information it stores.

Sample customers table
customer_idnamecity
101RahulDelhi
102PriyaMumbai
103AmitPune
104NehaDelhi

Customers stores customer identity and profile details.

Step 2 ยท Apply it

A shop stores customer details and order details. What is the best structure?

๐Ÿ”’ Pass the activity to unlock the related MCQ.

Lesson FAQ

Questions learners often ask

What You Will Learn in SQL Lesson 2

This lesson explains relational databases, table structure, primary keys, foreign keys, one-to-many relationships and composite keys through a small customer-orders example.

Why Keys Matter in Real Business

Keys help businesses identify records consistently and connect information across tables. A customer-order relationship makes it possible to analyse purchases without repeating all customer details on every order.

Common Beginner Mistakes

  • Assuming names are always unique.
  • Using a field with duplicate values as a primary key.
  • Confusing a primary key with a foreign key.
  • Repeating customer information unnecessarily in every order row.

Frequently Asked Questions

What is a primary key in SQL?

A primary key uniquely identifies each row in a table and cannot contain duplicate or NULL values.

What is a foreign key in SQL?

A foreign key refers to a key in another table and helps maintain valid relationships between records.

What is the difference between a primary key and a foreign key?

A primary key identifies a row in its own table. A foreign key stores a reference to a key in another table.

What is a composite key?

A composite key uses two or more columns together to uniquely identify a row.