Founder and CEO of Magna Data inc
Data Analytics Solutions and Corporate Training
University Graduate Degree in Computer Science
Tech Community Leader & Organizer in South
Proudly Nerd - Always Learning - Naturist –
Love Animals, good Books & the Beach
Entrepreneur - Consultant, Trainer, Speaker
Miami/Fort Lauderdale Area
Database > Tables > Rows > Columns
ERD: display entities
and how they are
Primary Keys (PK):
each record in a table
Foreign Keys (FK):
refers to the Primary
Key in another table
About the SQL Language
Structured Query Language
SQL / SEQUEL (Structured English Query Language)
Interact with Relational Databases
Comes from Relational Algebra & Calculus.
Codd, Chamberlin & Boyce.
SQL history by Chamberlin, here: https://ieeexplore.ieee.org/document/6359709
Declarative Language vs Procedural/imperative language
SQL Standard defined by ANSI (American National Standards Institute)
Vendors variations and extensions.
Extensions to SQL Language
Add Procedural Programming Language Functionality (Functions,
Cursors, arrays, loops, Control of Flows, etc)
Oracle PL/SQL Procedural Language/SQL
Microsoft SQL Server T-SQL Transact-SQL
Informix SPL Stored Procedural Language
MySQL SQL/PSM SQL/Persistent Stored Module
PostgreSQL PL/pgSQL Procedural Language/PostgreSQL SQL
SAP R3 ABAP Advance Business Application Programming
MariaDB SQL/PSM SQL/Persistent Stored Module
DML - Syntax
SELECT Column1, Column2, … FROM Table1
SELECT Column1, Column2, … FROM Table1 WHERE Condition
INSERT INTO Table1 (Column1,Column2,…) VALUES(Value1,Value2,…)
UPDATE Table1 SET Column1=Value1, Column2=Value2,…
UPDATE Table1 SET Column1=Value1, Column2=Value2,… WHERE Condition
DELETE FROM Table1
DELETE FROM Table1 WHERE Condition
DML – Syntax - Examples
• SELECT FirstName, LastName, email, DoB, FROM Customer;
• UPDATE Customer SET LastName=‘Smith’ WHERE CustomerID=123;
• INSERT INTO Customer(FirstName, LastName, email)
VALUES (‘Jane’, ’Doe’, ’Jdoe@gmail.com’);
• DELETE FROM Customer WHERE CustomerID = 123;
SELECT Column1, Column2
Boolean operators/Logical Operators AND, OR, NOT
=,<>,<=,>. Some DBs inequality: !=,^=,<>
Connect to me at: Cecilia@MagnaDataSolutions.com
Notas do Editor
Relational Databases store data organized i Tables that contains rows and columns
Data is typically structured across multiple tables, which can be joined together via a primary key or a foreign key.
Orders can have 1 or many order lines here, but one OrderLine/Detail belong to only
There is a SQL language standard defined by the American National Standards Institute (ANSI). Each vendor adds their own variations and extensions.
Declarative Language (define the output) vs Procedural/imperative language (sequence of instructions)
Declarative languages express the logic of a computation without describing its control flow in detail. Declarative programming stands in contrast to imperative programming via imperative programming languages, where control flow is specified by serial orders (imperatives).
T-SQL expands on the SQL standard to include procedural programming, local variables, various support functions for string processing, date processing, mathematics, etc. and changes to the DELETE and UPDATE statements.
Stored procedures in SQL Server are executable server-side routines. The advantage of stored procedures is the ability to pass parameters.
Data Definition Language (DDL) is the set of SQL statements that handles the definition of database objects, such as tables, views, and procedures. DDL includes statements such as CREATE, ALTER, and DROP.
Data Manipulation Language (DML) is the set of SQL statements that focuses on querying and modifying data. DML statements include SELECT, INSERT, UPDATE, and DELETE.
Data Control Language (DCL) is the set of SQL statements used to manage security permissions for users and objects. DCL includes statements such as GRANT, REVOKE, and DENY.
Add an example for each and the outcome as a pop up animation
SQL Keywords are case sensitive. Some DB configurations are setup to be case sensitive for Tables and Column names. This will be referred as the Collation. It can be setup at a Database Level, Table level or column level.
SQL Server default collation is case insensitive.
PostgreSQL is Case Sensitive by default
Show *, columns selection, alias,
Show some filtering options such as LIKE , =, BETWEEN, AND, OR, NOT, IN, ANY, SOME
Comparing to NULL returns UNKNOWN when using ANSI. SQL Server lets you turn ANSI NULL OFF and use other operators that will return TRUE or FALSE
There are vendors built-in functions to handle nulls
SELECT FirstName, ISNULL(MiddleName, 'None') AS MiddleIfAny, LastName FROM Sales.Customer;
In is more meticulous, goes thru the entire set
Exists, we don’t care how many times, if it finds it, then it is true, otherwise is null
Most popular functions
They are used in the select and having
Maybe mention DISTINCT?
NULL affects AVG
Now that you've seen what each clause does, let's look at the order in which SQL Server actually evaluates them:
The FROM clause is evaluated first, to provide the source rows for the rest of the statement. A virtual table is created and passed to the next step.
The WHERE clause is next to be evaluated, filtering those rows from the source table that match a predicate. The filtered virtual table is passed to the next step.
GROUP BY is next, organizing the rows in the virtual table according to unique values found in the GROUP BY list. A new virtual table is created, containing the list of groups, and is passed to the next step. From this point in the flow of operations, only columns in the GROUP BY list or aggregate functions may be referenced by other elements.
The HAVING clause is evaluated next, filtering out entire groups based on its predicate. The virtual table created in step 3 is filtered and passed to the next step.
The SELECT clause finally executes, determining which columns will appear in the query results. Because the SELECT clause is evaluated after the other steps, any column aliases (in our example, Orders) created there cannot be used in the GROUP BY or HAVING clause.
The ORDER BY clause is the last to execute, sorting the rows as determined by its column list.
Most Common JOINS
Allow us to combine tables together