Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

SQL

Introduction class 2024_ITACSENT


Accent IT Staffing Inc
What is SQL?

➔ Structured Query Language


➔ We use it to manipulate, manage
➔ SQL has Syntax Rules
What is DATA?
➔ Information or Facts or Records of
Information
➔ Is a collection of facts and figures, numbers,
words, measurements, of observations or
even just descriptions of things

Example:
Car insurance: to issue you a policy which
information they will be collecting from
you?
To issue you a policy which information will a car insurance company
collect from you?
⮚ Age
⮚ Gender
⮚ Location
⮚ Driving Record
⮚ Number of Accidents
⮚ Number of Years Driving
⮚ Car Manufacturer
⮚ Car Model
⮚ Car Mileage
⮚ Vehicle Identification number
⮚ Number of miles driven per week
⮚ Car Usage
⮚ Financed / Leased
What is DataBase?

➔ Storage/systems that allow


users to keep, organize and
manage Data.
➔ Is a complex program that
design to store data. It keeps
data correctly and retrieve
data efficiently.
Examples of Databases:
Microsoft Access – Ideal for small and mid-sized business
SQL Server – Ideal for mid sized business
Oracle – Ideal for large size business
Sybase – Ideal for large size business
FYI
What is the title of IT professional that sets up and
maintains DataBase?
DataBase Basic
DB is a collection of Tables
Tables in DB consist of Rows and Columns that holds Data:
• Rows in DB called Records
• Columns in DB called Fields/Attributes
Relational Database Management
System (RDBMS)

- RDBMS is a collection of tables


(relations) that store particular sets of
data in an organized way.
- RDBMS works on principle that each
table has a key field that uniquely
identifies each row and that these keys
can be used to connect one table to
another.
DataBase Schema
• Is the logical and definition of a
database structure that defines
objects in the Database
• DB Schema shows how tables
interconnected/related to each
other by the Primary Key and
Foreign Key
Primary Key
➔ Every table in database will
have a Primary Key (UID
unique identifier)
➔ PK is a column in the Table
that uniquely identifies each
record and the value is never
duplicated in the same table
➔ PK cannot contain NULL
Values
➔ Each table has only one
Primary Key
Foreign Key
➔ Is existence of PK in another
table
➔ Is a key used to link two tables
together
➔ It can accept Null Values
➔ We can have more than one
Foreign Key in a table.
The Primary Key and Foreign Key creates relationship
between 2 tables in Database
SQL Query
As a tester we mostly use statement / commands like the Select
statement to extract/select specific data from the database

➢ SQL is Case insensitive


➢ SQL statements Start with Keywords: Select, Insert, Create
etc…
➢ SQL statements End with Semicolon(;)

Semicolon is standard way to separate SQL statements


Select Statement
Retrieves Information from database table
How to SELECT multiple
Columns
Use Commas to separate columns
How to SELECT All
Columns
Use regular expression OR regex expression
➢ *(Everything)
TASK
BACKGROUND
You company recently hired a new HR Manager.

In your first meeting with the HR Manager you have briefed


him about the organization's culture of data based decision
making.

He has planned a company wide Human Resources Analysis.

To accomplish this the HR Manager has asked you to provide


him with the following information.
Task
The HR manager needs all the information from the Departments
table?
Task
The HR Manager needs the phone numbers of all employees ?

Select phone_number
From employees;
Task
He needs the department id column from the Employees table ?

Select department_id
From employees;
Task
The HR Manager needs all the records from Jobs table ?

Select *
From jobs;
Task
To understand the company structure he asked you to collect all
the information about department id and department name ?

Select department_id,
department_name
From departments;
Task
To understand the salary range for every job id he asked you to
collect the information about job id, max and min salary ?

Select job_id, max_salary,


min_salary
From jobs;
Data Types
There are a lot of Data Types. Common data types used are:
• Numbers – 1234
• VarChar - String, letters, characters (Variable Length)
• Date - 02/13/2011

Column in a database table can accept only ONE Data Type.


It is very strict rule.
DISTINCT
Eliminates all duplicate records in the result
Used right after the Select Statement
Where Statement
Used Restrict OR Filter Data
Comparison Operators
We have to use comparison operators with Where Statement
in order to limit the rows returned in the results.
Comparison Operators
Comparison Operators used to Compare Objects
Conditions could be Numeric Based OR Character Based

Numeric Based like Numbers (1234) datatype


We do not use single Quotes (‘ ’)

Character Based like varChar2 or Char data type


We must use Single Quotes (‘ ’)
Anything in Single Quotes is Case Sensitive.
TASK
BACKGROUND
You had a stand up meeting in the morning today
where the new HR Manager said the information you
provided earlier was indeed very useful.

He then asked you to help him collect some further


information based on his preliminary analysis.
Task
After the stand up meeting, the HR Manager need to know about
the salary of employee 120?

Select salary
From employees
Where employee_id = 120;
Task
He asked you to collect all the unique job ids from the employees
table?

Select distinct job_ids


From employees
Task
The HR Manager needs to know the first name, job id, salary for
all employees who earn less than or equal to 10,000 monthly

Select first_name, job_id, salary


From employees
Where salary <= 10000
Task
The HR Manager wants to know all the information for Stock
Clerks.

Select *
From employees
Where Job_id = ‘ST_CLERK’
Task
Finally he needs you to gather unique manager ids from
departments.

Select distinct manager_id


From departments
Sam
Desk: 571-427-7938
Cell: 703 340 8557 (whatsapp/call)
Email: sameer@meritekinc.com

THANK YOU
QUESTIONS & ANSWERS

You might also like