0
0
SQLquery~5 mins

Relational model mental model in SQL

Choose your learning style9 modes available
Introduction
The relational model helps us organize data in tables so we can easily find and use information.
When you want to store customer information like names and phone numbers.
When you need to keep track of orders and which products were bought.
When you want to link employees to their departments.
When you want to quickly search for data using simple questions.
When you want to keep data organized and avoid duplicates.
Syntax
SQL
CREATE TABLE table_name (
  column1 datatype PRIMARY KEY,
  column2 datatype,
  column3 datatype
);
Each table represents one type of thing, like customers or products.
Columns are the details about that thing, like name or price.
Examples
This creates a table named Customers with an ID, name, and phone number.
SQL
CREATE TABLE Customers (
  CustomerID INT PRIMARY KEY,
  Name VARCHAR(100),
  Phone VARCHAR(15)
);
This table stores orders with a link to the customer who made each order.
SQL
CREATE TABLE Orders (
  OrderID INT PRIMARY KEY,
  CustomerID INT,
  OrderDate DATE
);
Sample Program
This example creates an Employees table, adds three employees, and shows all the data.
SQL
CREATE TABLE Employees (
  EmployeeID INT PRIMARY KEY,
  FirstName VARCHAR(50),
  LastName VARCHAR(50),
  Department VARCHAR(50)
);

INSERT INTO Employees (EmployeeID, FirstName, LastName, Department) VALUES
(1, 'Alice', 'Smith', 'Sales'),
(2, 'Bob', 'Jones', 'HR'),
(3, 'Carol', 'Taylor', 'IT');

SELECT * FROM Employees;
OutputSuccess
Important Notes
The relational model uses tables with rows and columns, like a spreadsheet.
Each row is one record, and each column is a field or attribute.
Primary keys uniquely identify each row to avoid confusion.
Summary
The relational model organizes data into tables with rows and columns.
Tables represent things, columns represent details, and rows represent records.
Primary keys help keep each record unique and easy to find.