Gomaa Intelligence.Data Hub
عربي

Foundations › SQL › Foundations: Databases

️ Foundations: Databases

The Relational Model: Tables, Rows, Columns and Keys

Lesson 2 / 14· 7 min

In a relational database data is split across linked tables instead of one giant table. Each table represents one thing: customers, orders, products.

Parts of a table

TermMeaningExample
TableA set of rows of the same kindcustomers
Row / RecordOne customer with all detailsid=1, Ahmed Ali, Cairo
Column / FieldOne property for every rowname or city
Data typeThe kind of values a column allowsnumber, text, date
▶ Try it yourself

Here is the products table: each row is a product, each column a property. Open in SQL Lab

Primary key

A column (or more) whose value is unique, never repeated and never empty, identifying a row exactly. In customers it is id, like a person's national ID.

Foreign key

A column in one table pointing to the primary key of another. In orders, customer_id points to customers.id, so we know which customer each order belongs to.

▶ Try it yourself

Notice customer_id: a number pointing to a customer in the customers table. Open in SQL Lab

customersid PKnamecityemailordersid PKcustomer_id FKorder_datestatusproductsid PKnamecategorypriceorder_itemsid PKorder_id FKproduct_id FKquantity1N1N1N
Relationship diagram of the sample shop database

Why split the data?

If we wrote the customer's name and city in every order we would repeat the same data thousands of times, and if the city changed we would edit thousands of rows and might miss some. Splitting stores each fact once.

For advanced readers Schema and constraints

The schema is the database design: tables, columns, types and constraints (PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK) that protect data from errors before they get in.

❓ In the orders table, customer_id is a…

❓ Can a primary key value repeat in a table?

Summary
  • A table represents one thing, a row is a record, a column a property.
  • A primary key identifies a row; a foreign key links to another table.
  • Splitting prevents repetition and makes edits easier.

Want an expert to do it for you?

Gomaa Intelligence turns your data into clear reports and decisions. Tell us your problem and we will reply.

Get your data analyzed by an expert ↗