Databases
Option A
The British International School, Istanbul
Data vs. Information
Data |
Raw facts |
Unprocessed |
No context |
Just text and numbers |
Information |
Data + context |
Processed and structured |
Interpreted by the user |
Data is given meaning |
Jason got a 95/100 on the Final Exam
Jason scored 12 points higher than the
class average
Jason got the 2nd highest score in the class
The British International School, Istanbul
What is a database?
The British International School, Istanbul
The British International School, Istanbul
Why use a database?
The British International School, Istanbul
Data Validation vs. Data Verification
Data Verification | Data Validation |
|
|
The British International School, Istanbul
What is a table?
The British International School, Istanbul
What is a table? (2)
The British International School, Istanbul
What is an entity?
real-world object or person
The British International School, Istanbul
What is a primary key?
The British International School, Istanbul
What is a foreign key?
The British International School, Istanbul
The British International School, Istanbul
Data Types
Data Types | Description | Examples |
Text | Combination of letters, numbers, symbols (treated as text) - even if number, no mathematical operation possible | “Amith” “X97BF” “$LLF” “34” “3” |
Character | An individual letter, number, or symbol - even if number, no mathematical operation possible | “3” “A” “#” “b” |
Boolean | True/False or Yes/No | True False |
Integer | A whole number | 5, 29, -31 |
Real | A decimal number | 33.1, 22.39, 2.10 |
Datetime | A date and/or time | 12:30 5/9/2022 7/11/2022 03:35 |
The British International School, Istanbul
Creating our first table
The British International School, Istanbul
Get All Values in a Field
SELECT ProductName FROM Products
SELECT ProductName, Price FROM Products
Table Name: Products
The British International School, Istanbul
SELECT Statements
SELECT - Used for SQL statements to get a set of data from table
FROM - Used to specify the table from which the data will come
SELECT ProductName, Price FROM Customers
Field(s)
Table
The British International School, Istanbul
Get All Values in a Field According to Criteria
SELECT ProductName FROM Products WHERE Price > 20
SELECT * FROM Products WHERE SupplierID <> 1
Table Name: Products
The British International School, Istanbul
Get All Values in a Field that Contain a String
SELECT * FROM Products WHERE ProductName LIKE ‘A’
SELECT ProductName FROM Products WHERE ProductName LIKE ‘Cha’
Table Name: Products
The British International School, Istanbul
Simple vs. Complex Queries
SELECT ProductName FROM Products WHERE Price > 20
SELECT ProductName FROM Products WHERE Price > 20 AND PRICE < 22
The British International School, Istanbul
SQL Cheat Sheet
Get Field Data
SELECT Field1, Field2, …* FROM TableName
Get Field Data According to Criteria
SELECT Field1, Field2, …* FROM TableName WHERE Some_Criteria
Get All Values in a Field That Contain A String
SELECT Field1, Field2, …* FROM TableName WHERE Some_Criteria LIKE Some_String
The British International School, Istanbul
What is a secondary key?
https://programmerbay.com/difference-between-pri mary-key-and-secondary-key/
The British International School, Istanbul
Secondary Key vs. Foreign Key
Primary Key | Secondary Key |
Can uniquely identify records | Can uniquely identify records |
Cannot be NULL | Can be NULL |
Only one primary key field possible | Multiple secondary key fields possible |
The British International School, Istanbul
What is a candidate key?
https://programmerbay.com/difference-between-pri mary-key-and-secondary-key/
The British International School, Istanbul
What is a composite primary key?
- When one field is not enough to uniquely identify records, but two fields together can functions as a primary key
Name | Birthday | Grade |
Amith | 02/04/2003 | 98 |
John | 27/03/2008 | 77 |
Ali | 09/09/2009 | 95 |
Sofia | 11/11/2011 | 100 |
The British International School, Istanbul
What is a database schema?
The British International School, Istanbul
The British International School, Istanbul
What is a relational database?
The British International School, Istanbul
Referential Integrity
The British International School, Istanbul
Database Management Systems (DBMS)
The British International School, Istanbul
DBMS Components
The British International School, Istanbul
Data Dictionary
The British International School, Istanbul
Data Dictionary Example
The British International School, Istanbul
Concurrency
written by one user while at the same time it is being written by a different user
take place sequentially
The British International School, Istanbul
Role of DBMS in Security
The British International School, Istanbul
Database Transactions
statements that are executed sequentially, as if they were one command
The British International School, Istanbul
The British International School, Istanbul
ACID (Atomicity, Consistency, Isolation, Durability)
DBMS follows ACID principles for transactions:
The British International School, Istanbul
What is the purpose of transactions?
The British International School, Istanbul
Data Integrity
The British International School, Istanbul
Data Redundancy
The British International School, Istanbul
Data Redundancy - Pros & Cons
Pros |
Faster data access speeds - more locations from which data can be accessed |
Better data protection - in case of loss, data can be replaced from other location(s) |
Cons |
Data inconsistency - if data is updated at one location, other locations may not be updated as well |
More storage space required (expensive) |
The British International School, Istanbul
Normalization
contains the same data
information
The British International School, Istanbul
Why use normalization?
The British International School, Istanbul
The Normal Forms
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
Normalization Steps
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
Normalization Advantages
The British International School, Istanbul
Anomalies
The British International School, Istanbul
Anomaly Examples
The British International School, Istanbul
Database Administrator (DBA)
Responsible for:
The British International School, Istanbul
Database Definition Language (DDL)
The British International School, Istanbul
Data Modelling
The British International School, Istanbul
Conceptual, Logical, Physical
The data model will take the information from the conceptual schema and logical schema to informs the physical model for the development of the database:
The British International School, Istanbul
Advantages of Data Modelling
The British International School, Istanbul
ERD (Entity Relationship Diagrams)
An ERD represents the relationship between different entities in a database.
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
HL
The British International School, Istanbul
What is an object-oriented database?
The British International School, Istanbul
Advantages of Object-Oriented Databases
The British International School, Istanbul
Disadvantages of Object-Oriented Databases
The British International School, Istanbul
Data Warehouse
The British International School, Istanbul
Data Warehousing Advantages
The British International School, Istanbul
ETL (Extraction, Transformation, Loading)
Process by which data from multiple sources is collected, processed and sent to the data warehouse
The British International School, Istanbul
Data Warehouse vs. Database
Data Warehouse | Database |
Mainly stores historical data | Mainly stores current data |
TB’s of Data | GB’s of Data |
Data maintained over time | Data always up-to-date |
Users mostly have read-only access | Users usually have read/write access |
Used for everyday transactions | Used for decision support |
Optimized for more complex queries across larger sets of data | Optimized for lightning-fast CRUD (Create, Read, Update, Delete) queries on individual rows |
Deals with relatively small number of users | Can handle thousands of users |
The British International School, Istanbul
What is data mining?
The British International School, Istanbul
Data Mining Pros & Cons
Pros | Cons |
Helps to understand behaviors, trends, and hidden patterns | May utilize sensitive personal information |
Helps detect risk and fraud | Aggregated personal data may compromise privacy or anonymity |
Helps analyze large amounts of data very quickly | Expensive |
| Requires large databases |
The British International School, Istanbul
Supervised Vs Unsupervised Learning
Supervised and unsupervised learning are two main types of machine learning.
In supervised learning, the model is trained with labeled data where each input has a corresponding output.
On the other hand, unsupervised learning involves training the model with unlabeled data which helps to uncover patterns, structures or relationships within the data without predefined outputs.
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
Supervised Vs Unsupervised Learning
The British International School, Istanbul
Supervised Vs Unsupervised Learning
The British International School, Istanbul
Cluster Analysis
The British International School, Istanbul
Classification
The British International School, Istanbul
Cluster Analysis vs. Classification
Cluster Analysis | Classification |
Unsupervised Learning | Supervised Learning |
Unlabeled data samples as input | Labeled data samples as input |
No prior knowledge of relationships in data | Prior knowledge of relationships in data |
Outputs groups of data points | Outputs groups of data points |
The British International School, Istanbul
Association Analysis
relationships in datasets
The British International School, Istanbul
Link Analysis
The British International School, Istanbul
Deviation Detection
Sudden pro-candidate or
anti-candidate sentiment in a particular state
The British International School, Istanbul
Spatial Database
The British International School, Istanbul
Data Segmentation
The British International School, Istanbul
Supplement
Option A Database
IB Computer Science
The British International School, Istanbul
Intro
Caffeine +
ChatGPT +
Love of CS = The CS Classroom
The British International School, Istanbul
The British International School, Istanbul
SELECT Statements
SELECT - Used for SQL statements to get a set of data from table
FROM - Used to specify the table from which the data will come
SELECT ProductName, Price FROM Customers
Field(s)
Table
The British International School, Istanbul
Get All Values in a Field
SELECT ProductName FROM Products
SELECT ProductName, Price FROM Products
Table Name: Products
The British International School, Istanbul
SELECT ProductName FROM Products
Product Name |
Chaise |
Chang |
Aniseed Syrup |
Chef Anton’s Cajun Seasoning |
Chef Anton’s Gumbo Mix |
The British International School, Istanbul
SELECT ProductName,Price FROM Products
Product Name | Price |
Chaise | 18 |
Chang | 19 |
Aniseed Syrup | 20 |
Chef Anton’s Cajun Seasoning | 22 |
Chef Anton’s Gumbo Mix | 21.35 |
The British International School, Istanbul
Get All Values in a Field According to Criteria
SELECT ProductName FROM Products WHERE Price > 20
SELECT * FROM Products WHERE SupplierID <> 1
SELECT ProductID, Price FROM Products WHERE Price >= 18 and Price < 22 and Unit LIKE “36 boxes”
Table Name: Products
The British International School, Istanbul
SELECT ProductName FROM Products WHERE Price > 20
Product Name |
Chef Anton’s Cajun Seasoning |
Chef Anton’s Gumbo Mix |
The British International School, Istanbul
SELECT * FROM Products WHERE SupplierID <> 1
ProductID | Product Name | Price | SupplierID | CategoryID | Unit |
4 | Chef Anton’s Cajun Seasoning | 22 | 2 | 2 | 48 - 6 oz jars |
5 | Chef Anton’s Gumbo Mix | 21.35 | 2 | 2 | 36 boxes |
The British International School, Istanbul
SELECT ProductID, Price FROM Products WHERE Price >= 18 and Price < 22 and Unit LIKE “%boxes%”
ProductID | Price |
5 | 21.35 |
The British International School, Istanbul
Comparing Strings with LIKE and ‘==’
SELECT ProductName FROM Products WHERE Unit == “36 boxes”
SELECT ProductName FROM Products WHERE Unit LIKE “%boxes%”
The British International School, Istanbul
SELECT ProductName FROM Products WHERE Unit == “36 boxes”
Product Name
Chef Anton’s Gumbo Mix
The British International School, Istanbul
SELECT ProductName FROM Products WHERE Unit LIKE “%boxes%”
Product Name |
Chais |
Chef Anton’s Gumbo Mix |
The British International School, Istanbul
Table Name: Products
Sum
SELECT SUM(Price) FROM Products WHERE CategoryId = 2
SELECT SUM(Price)FROM Products WHERE Price <= 22
The British International School, Istanbul
Count (Counts how many records meet criteria)
SELECT COUNT(Price) FROM Products WHERE CategoryId = 2
SELECT COUNT(Price)FROM Products WHERE Price <= 22
Table Name: Products
The British International School, Istanbul
SQL Cheat Sheet
Get Field Data
SELECT Field1, Field2, …* FROM TableName
Get Field Data According to Criteria
SELECT Field1, Field2, …* FROM TableName WHERE Some_Criteria
The British International School, Istanbul
SQL Cheat Sheet (Part 2)
Calculate Sum
SELECT SUM(Field) FROM Table WHERE Some_Criteria
Count Number of Records
SELECT COUNT(Field) FROM Table WHERE Some_Criteria
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
Derived Fields
SELECT Total/3 AS Average FROM Students
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
JOINS
The British International School, Istanbul
SELECT
Customers.customer_id, Customers.first_name, Orders.amount
FROM
Customers INNER JOIN Orders ON Customers.customer_id == Orders.customer
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul