0% found this document useful (0 votes)
46 views27 pages

Quick Comparison of PostgreSQL and SQL Server

The document provides an overview of SQL and relational databases, detailing their structure, core concepts, and the differences between relational and non-relational databases. It emphasizes the importance of databases in managing large volumes of data, ensuring data integrity, and supporting complex queries. Additionally, it covers key database components such as tables, keys, relationships, and the installation process for SQLite and MySQL.

Uploaded by

sirjojo407
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views27 pages

Quick Comparison of PostgreSQL and SQL Server

The document provides an overview of SQL and relational databases, detailing their structure, core concepts, and the differences between relational and non-relational databases. It emphasizes the importance of databases in managing large volumes of data, ensuring data integrity, and supporting complex queries. Additionally, it covers key database components such as tables, keys, relationships, and the installation process for SQLite and MySQL.

Uploaded by

sirjojo407
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

SQL and

Relational databases
A database is an organized, electronic collection of data designed
for efficient storage, retrieval, updating, and management—
typically operated through specialized software known as a
Database Management System (DBMS)

Core Concepts
•Structure
Data is arranged in tables (rows = records, columns = fields), and
these tables are often linked via keys (e.g., primary and foreign keys)
to model real-world relationships.

•Queries
You use query languages like SQL to search, filter, join, and
manipulate the data, enabling complex reports and analysis.

•DBMS
Acts as the middle layer between users/applications and the
database, managing data integrity, security, backups, concurrency,
and performance
[Link] Databases (RDBMS)
1. Use structured tables and relationships.
2. Rely heavily on SQL.
3. Examples: MySQL, PostgreSQL, Oracle, SQL Server.

[Link]‑Relational Databases (NoSQL)


1. Include document stores (e.g., MongoDB), key‑value stores (e.g., Redis),
wide‑column, and graph databases.
2. Flexible schema, great for unstructured or semi-structured data and
massive scalability.

[Link] & Network Databases


1. Older models that store data in tree-like (hierarchical) or graph-like
(network) structures.

[Link]‑Oriented Databases
1. Designed to integrate with object-oriented programming languages,
storing data as objects.

[Link] Types
[Link] databases for machine learning, in-memory databases for
ultra-fast data access, cloud databases, and multimodel options
Why Databases Matter
•Handle large volumes of data efficiently at scale (millions to billions
of records).

•Ensure data integrity, consistency, and security through rules,


constraints, and roles

•Support concurrent users, robust backups, and reliable recovery.

•Are essential for analytics and decision-making, powering


applications from banking systems to social media via structured
queries and reporting tools
How Databases Differ from
Spreadsheets
Aspect Spreadsheet Database
Large, structured,
Size & Structure Smaller, flat
relational
Designed for
Multi‑user Limited concurrency
concurrent access
Enforced with
Schema Informal
constraints & types
Advanced queries,
Integrations Basic charts
transactions

Databases excel when you need to manage complex, structured data


reliably, especially across multiple users and large datasets
Why It Matters for AI Engineering
[Link] Handling: Almost all real-world data pipelines involve
structured data—SQL is the go-to tool for extraction and
preprocessing.

[Link] & Scale: Understanding indexes, query


optimization, and transactions helps build systems that can handle
millions of records efficiently.

[Link]: AI systems and feature stores often use relational


databases—knowing SQL is key to integrating data, debugging, and
maintaining pipelines.
•What: A language for managing structured relational data.
•Why: Universal, simple to learn, and essential for data-intensive work.
•How: Write SQL commands to query, insert, update, delete, and define
database structure.
•Where: Foundational in data analytics, backend systems, ML pipelines,
and beyond.
SQL stands for Structured Query Language. It's the standardized,
declarative programming language used to interact with relational
database management systems (RDBMS)—databases that store
data in tables (rows and columns) and define relationships between
them
Key Points

•Relational Model
Data is organized in tables. Relationships (like one-to-many, many-to-
many) are established via keys (e.g., foreign keys).

•Declarative & High-Level


Instead of writing step-by-step logic, you state what you want (e.g., "give
me all customers from Uganda") and the DBMS figures out how to get it.

•Main Command Types


•DQL (Query): SELECT – retrieve data
•DML (Manipulation): INSERT, UPDATE, DELETE – change data
•DDL (Definition): CREATE, ALTER, DROP – define schema
•DCL/TCL (Control/Transactions): GRANT, ROLLBACK, COMMIT –
manage permissions & ensure ACID properties
ACID Compliance
Ensures data operations are Atomic, Consistent, Isolated, and
Durable, critical for reliability

Widely Used
Fundamental across industries—finance, healthcare, social media,
business intelligence—and essential in applications like managing user
accounts, transaction records, analytics pipelines, etc.

Universal with Dialects


While there’s a standard (ANSI/ISO), various RDBMS vendors—like
Oracle, Microsoft SQL Server (T‑SQL), PostgreSQL, MySQL—have their
own SQL "flavors" with added features
A relational database is a system that stores structured data in
tables (also called relations), where each table consists of rows
(records) and columns (attributes). It's based on a model
introduced in the 1970s by E. F. Codd
Relational databases are widely used in industries like finance,
healthcare, e-commerce, CRMs, and ERP systems—basically
anywhere structured, interconnected data is crucial
Fundamental Concepts
[Link]
Each represents an entity type (e.g., Customers, Orders). Rows are
instances (like Alice, Order #123) and columns describe attributes
(name, date, amount)

[Link] & Relationships


•Primary key: a unique identifier for each row within a table (like
CustomerID)

•Foreign key: a column in one table that refers to the primary key of
another, enabling relationships (e.g., linking [Link] to
[Link])
•Schema & Integrity
A defined schema enforces rules: data types, required fields,
uniqueness, and relational integrity. This ensures data remains
accurate and consistent .

•SQL Support & ACID Principles


Relational databases use SQL for querying and enforcing ACID
properties:

•Atomicity: operations are all-or-nothing


•Consistency: database remains valid before/after transactions
•Isolation: concurrent transactions do not interfere
•How
Durability: committed
They Work changes are permanent
in Practice
Suppose you have two tables:
•Customers: CustomerID (PK), Name, Email
•Orders: OrderID (PK), CustomerID (FK), OrderDate
Query example:
SELECT [Link], [Link]
FROM Customers AS c
JOIN Orders AS o ON [Link] = [Link];

This returns every customer’s name alongside their orders by linking rows between
Benefits

Benefit Description
Easy to understand data in
Structured & Intuitive
tables and relationships
Prevents duplicates and
Data Integrity & Accuracy
enforces constraints
SQL enables complex
Powerful Queries operations across multiple
tables
Role-based access, multi-user
Security & Collaboration
support
Reliable transactions for
ACID-compliance
mission-critical use
TABLES,COLUMNS,ROWS &
KEYS
What Makes a Table (Relation)?
[Link]: rows & columns
1. Each row (or tuple) is a data record—an instance of the entity the table
represents.
2. Each column (or attribute) specifies a particular property, with a defined
data type (e.g. integer, string, date)

[Link] & Uniform


1. Every cell holds a single (atomic) value—no lists or nested tables allowed
2. All entries in a column share the same data type/domain .

[Link] inherent order


1. Neither the order of rows nor columns holds meaning

[Link] of rows
1. No two rows may be identical—this ensures each record is uniquely
identifiable
Why Organize into Tables?
This structure supports:
•Projects normalized design: eliminates redundancy—each fact is stored
exactly once
•.
•Data consistency: foreign key constraints prevent “dangling” references—data
remains accurate and meaningful
What is a Column?
•A column (or attribute, field) defines a named data attribute in a
table.

•Every entry in that column must be of the same data type or domain
(e.g. integer, date, string)

•You can think of it as a named vertical slice: e.g., in a “Customer”


table, columns might be CustomerID, Name, Email.

What is a Row?
•A row (or tuple, record) is one data instance in a table—a horizontal
collection of values, one per column

•All rows in a table must follow the same structure defined by the
columns

•Each row represents an individual entity or fact—e.g., one customer or


one order
Key Properties
•Atomicity: Each cell (row × column) holds exactly one value—no lists
or nested data

•Uniformity: Values in a column share the same data type and


domain

•No inherent order: Neither rows nor columns have a meaningful


order; rearranging them doesn’t affect the model

•Uniqueness: No duplicate rows allowed—every row must be


distinguishable, typically via a prima
Why This Matters
•Ensures data integrity and consistency—every cell is predictable and
standardized.

•Enables powerful querying with SQL (e.g., filtering by column values,


joining with other tables).

•Aligns with First Normal Form in normalization—no multi-valued


fields, structured, relationally sound
Together: The Table

A table is a named collection of related columns and rows:

CustomerID (INT) Name (VARCHAR) Email (VARCHAR)


1 Alice alice@[Link]
2 Bob bob@[Link]

•Here, CustomerID, Name, Email are columns, each with a defined type,
representing a customer’s attributes.

•Each horizontal line is a row, representing a specific customer instance.


KEYS Enforcing Structure & Integrity
1. Super Key
•A super key is any set of one or more columns that uniquely
identify each row in a table.
•It may include extra, unnecessary columns beyond what's strictly
needed
2. Candidate Key
•A candidate key is a minimal super key—no subset of it can still
uniquely identify rows
•A table can have multiple candidate keys; one is chosen as the primary
key, the rest become alternate
•Example:
“A candidate key is any set of attributes a user could pick to be that
primary key… you need to pick a new primary key, so you review your
candidate keys”
3. Primary Key
•The primary key is a chosen candidate key that uniquely identifies
each row and cannot be NULL. (e.g., CustomerID)
•Only one primary key per table.
•Can be single-column or composite (multi-column)
4. Alternate (Unique) Key
•Any other candidate key not used as the primary key.
•Enforced via a UNIQUE constraint instead of PRIMARY KEY (e.g.,
email or SSN)

5. Surrogate Key
•A surrogate key is an artificial column (e.g. auto-incrementing ID or
UUID) with no business meaning, used as the primary key
•Preferred when natural keys may change or are cumbersome—
provides stability, performance, and uniformity

6. Composite Key
•A key made of two or more columns that together uniquely identify
a row
•Useful when no single column suffices (e.g., in junction tables for
many-to-many relationships).
7. Foreign Key
•A foreign key is a column (or columns) in one table that
references a key (typically primary) in another table, enforcing
referential integrity
•Allows, but does not require, NULL values unless specified NOT
NULL . (e.g., [Link] -> [Link])
Visual Summary
Key Type Description
Any set of columns that uniquely identify
Super Key
rows
Candidate Key Minimal super key (no extra columns)
Chosen candidate key, not null, single
Primary Key
per table
Other candidate keys, defined with
Alternate Key
UNIQUE
Artificial primary key (e.g., auto-
Surrogate Key
increment ID)
Composite Key Key composed of multiple columns
References a key in another table;
Foreign Key
maintains referential integrity

Why They Matter


•Entity integrity: Primary keys ensure each record is unique and identifiable.
•Referential integrity: Foreign keys guarantee that relationships between
tables remain valid.
•Normalization & design clarity: Candidate, alternate, and composite keys
help maintain structure and avoid redundancy.
•Performance and flexibility: Surrogate keys simplify joins and allow stable
RELATIONSHIPS
In database design, a relationship defines how two tables interact
by linking records through keys—usually a primary key in one table
and a foreign key in another.

How It Works
•Primary key: Unique identifier in a table (e.g., StudentID).

•Foreign key: A column in another table that references the primary


key, creating the relationship.

•Referential integrity: Ensures every foreign key value matches an


existing primary key and prevents orphaned records.

Why Relationships Matter


•Reduce data redundancy by avoiding duplicate information.

•Uphold data integrity, ensuring all links between tables are valid.

•Enable efficient queries across tables using JOINs to pull related


data.
Relationship Types

1. One‑to‑One (1:1)
Each row in Table A corresponds to exactly one row in Table B, and vice
versa.
Best applied when splitting occasionally used or sensitive data into
separate tables.
Example:
Person(PersonID PK, Name, …)
PersonContact(PersonID PK, Phone, Email, …)

Here, [Link] is both PK and FK to [Link]


2. One‑to‑Many (1:N)
A row in Table A can be linked to many rows in Table B, but each row
in B links to one in A.
Example:
Customers(CustomerID PK, Name, …)
Orders(OrderID PK, CustomerID FK, Date, …)

One customer → many orders. In a simplified ER design, the child


3. Many‑to‑Many (M:N)
Both tables can have multiple matches in the other. This is
implemented using a junction (or associative) table that breaks it
into two 1:N relationships.

Example:
Students(StudentID PK, …)
Courses(CourseID PK, …)
Enrollments(StudentID FK, CourseID FK, PRIMARY
KEY(StudentID,CourseID))

A student can enroll in multiple courses, and a course can have


multiple students
Design Tips
•Normalization: Split tables so that each fact is stored once, reducing redundancy.
Then link tables via keys
•Relationships by FK:
•1:N — add FK to the child (many-side) table.
•1:1 — child table’s PK is also its FK to parent.
•M:N — create a junction table with FKs from both tables, often using a
composite PK Enforce constraints: Use FOREIGN KEY clauses to maintain data
consistency and integrity
Installing SQLite
Windows
[Link] Winget (recommended):
Open Command Prompt or PowerShell as Administrator and run:
winget install [Link]
This installs the sqlite3 CLI tool

2. Add GUI (optional):


You can also install DB Browser for SQLite:
winget install [Link]
This gives you a friendly interface for managing .db files

Manual install:
•Download the "Precompiled Binaries for Windows" from [Link],
unzip to a folder like C:\sqlite3\.
•Add this folder to your PATH environment variable so the sqlite3
command is recognized globally .
Linux (e.g., Ubuntu)
Simply run:
sudo apt update
sudo apt install sqlite3
Then verify with:
sqlite3 --version

Installing MySQL
Windows
[Link] MySQL Installer from the
MySQL Community Downloads page — choose the web installer or full MSI
[Link]+[Link]+[Link]+11.

[Link] the MSI and follow the wizard:


•Choose "Developer Default" or "Full."
•Installer checks requirements and downloads necessary components.
•Configure MySQL Server: select standalone development setup, TCP/IP
(default port 3306), and strong password encryption.
•Set root password, optionally create additional user.
•Configure MySQL as a Windows Service to start at boot.
•Finish and validate connection via MySQL Workbench or CLI
3. Verify installation:
•Open MySQL Workbench or MySQL Command Line Client.
•Log in with root user to confirm success.

Linux (Ubuntu/Debian)
[Link] package repo:
sudo apt update

[Link] server:
sudo apt install mysql-server

3. Secure installation:
sudo mysql_secure_installation

Follow prompts to set root password, remove anonymous users, restrict


remote root login, and remove test database
4. Start and enable service:
sudo systemctl start mysql
sudo systemctl enable mysql
5. Log in to verify:
mysql -u root -p
Quick Comparison

Feature SQLite MySQL


❌ Requires a running
Serverless ✅ Embedded in apps
server
Moderate with
Setup Complexity Very easy
installer/config steps
DB Browser, MySQL Workbench
GUI Available
SQLiteStudio (Windows/Linux client)

You might also like