Professional Documents
Culture Documents
Intro To SQL 2022 Edition by University of Jordan
Intro To SQL 2022 Edition by University of Jordan
03/23/2024 2
The Most popular database
management system (DBMS)
03/23/2024 3
Microsoft SQL
Server 2019
Express
Installation link
https://www.microsoft.com/en-us/Download/details.aspx?id=101064
SQL Server 2019 Express Installation
03/23/2024 5
SQL Server 2019 Express Installation
03/23/2024 8
SQL Server 2019 Express Installation
03/23/2024 15
SQL Server Management Studio (SSMS)
03/23/2024 16
SQL Server Management Studio Installation
03/23/2024 19
Starting SQL Server Management Studio
03/23/2024 21
SQL (Structured Query Language) used to manage and
manipulate relational databases. The following are the types
of SQL commands:
03/23/2024 22
SQL Operators
03/23/2024 23
AND Truth Table
03/23/2024 24
OR Truth Table
03/23/2024 25
NOT Truth Table
03/23/2024 26
Primary Key
A primary key is a unique identifier for each record (row).
The primary key is used to enforce the integrity of the data by
ensuring that each record has a unique identifier.
The following are the conditions that a primary key must meet:
1.Uniqueness:
• Each value in the primary key column must be unique.
2.Not-null:
• The primary key values cannot be null (empty).
3.Irreversibility:
• The primary key values cannot be changed once they are assigned.
03/23/2024 27
Foreign Key
A foreign key is a field in a relational database table that is used to establish a
relationship with another table. The foreign key in one table is used to reference the
primary key in another table.
The following are the conditions that a foreign key must meet:
1. Referenced Key:
•The foreign key must reference a primary key in another table.
2. Not-null:
•The foreign key values cannot be null (empty).
3. Consistency:
•The values in the foreign key must correspond to the values in the referenced
primary key.
03/23/2024 28
PK Examples
03/23/2024 29
FK Example
03/23/2024 30
SQL Comments
03/23/2024 31
SQL Data Definition Language (DDL) commands
CREATE TABLE Example 1 :
03/23/2024 33
Text: CREATE TABLE EmployeeProjects
CREATE View :
03/23/2024 34
Text: CREATE VIEW EmployeeInfo AS
Drop Command :
03/23/2024 35
Truncate Command :
03/23/2024 36
Alter Table Command :
03/23/2024 37
SQL Data Manipulation Language (DML) commands
03/23/2024 38
SELECT Statement example 1
03/23/2024 40
SELECT Statement example 4
Where Clause
03/23/2024 41
SELECT Statement example 5
Where Clause and patterns Like Operator
% anyone
? any characters
character (Oracle) _ any one character (SQL
Server)
03/23/2024 42
SELECT Statement example 6
Where Clause and patterns Like Operator
03/23/2024 43
SELECT Statement example 7
Where Clause and between Operator
03/23/2024 44
SELECT Statement example 8
Where Clause and (IN) Operator
03/23/2024 45
SELECT Statement example 9
Where Clause and is NULL Operator
03/23/2024 46
SELECT Statement example 10
Using mathematical expression and alias name
03/23/2024 47
SELECT Statement example 11
Using mathematical expression and alias name
03/23/2024 48
SQL Aggregate Functions
SQL aggregate functions are functions that perform a calculation on
a set of values and return a single value. Some of the most commonly
used SQL aggregate functions are:
03/23/2024 49
SQL Aggregate Functions Example 1
03/23/2024 50
SQL Aggregate Functions Example 2
Group By clause
03/23/2024 51
SQL Aggregate Functions Example 3
03/23/2024 52
SQL Aggregate Functions Example 4
03/23/2024 53
SQL Aggregate Functions Example 5
03/23/2024 54
SQL Aggregate Functions Example 6
03/23/2024 55
SQL Aggregate Functions Example 7
Having clause
03/23/2024 56
SQL Aggregate Functions Example 8
Relatively complex example
03/23/2024 57
Order By Clause
03/23/2024 58
SQL Aggregate Functions Example 9
Order By
03/23/2024 59
Insert statement
03/23/2024 60
Update Statement
03/23/2024 61
Delete Statement
03/23/2024 62
Joining two Table
03/23/2024 63
Joining two Table with alias
03/23/2024 64
Joining three Table with alias
03/23/2024 65
Create User (Oracle)
03/23/2024 66
SQL Data Control Language (DCL) commands
03/23/2024 67
SQL Data Control Language (DCL) commands
03/23/2024 68
SQL (DCL) commands - Commit
03/23/2024 69
SQL (DCL) commands - Commit
03/23/2024 70
SQL (DCL) commands - Rollback
03/23/2024 71
Special Ms-Sql Server Functions
03/23/2024 72
SQL String Functions – Examples 1
03/23/2024 73
SQL String Functions – Examples 2
03/23/2024 74
SQL String Functions – Examples 3
03/23/2024 75
SQL String Functions – Examples 4
03/23/2024 76
SQL String Functions – Examples 5
03/23/2024 77
SQL String Functions – Examples 6
03/23/2024 78
SQL numbers Functions
03/23/2024 79
SQL numbers Functions example 1
03/23/2024 80
SQL numbers Functions example 2
03/23/2024 81
SQL numbers Functions example 3
03/23/2024 82
SQL numbers Functions example 4
03/23/2024 83
SQL numbers Functions example 5
03/23/2024 84
Oracle to_char function
03/23/2024 85
Oracle to_date function
03/23/2024 86
Oracle to_number function
03/23/2024 87
Oracle to_number function
03/23/2024 88
SQL server Date Conversion
List of Date conversion Code
03/23/2024 89
SQL server Date Conversion Examples 1
03/23/2024 90
SQL server Date Conversion Examples 2
03/23/2024 91
Case Study
SELECT
CONCAT('Employee Name: ',REPLACE(UPPER(firstname), 'A', '@'),' ' ,LastName) AS NewEmpName,
CONVERT(NVARCHAR, HireDate, 113) AS HireDate,
Salary AS OriginalSalary,
FLOOR(Salary * 0.20) AS BonusValue ,
FLOOR(SQRT(Salary)) AS DeductionValue ,
Salary + (FLOOR(Salary * 0.20) - FLOOR(SQRT(Salary))) AS NewSalary
FROM Employee
where Gender is not null
group by firstname,HireDate,Salary,LastName
having MIN(EmployeeID) > 0
order by Salary desc;
03/23/2024 92
Case Study Output
03/23/2024 93
Select data depend on another select
Get the employee who haven't projects
SELECT EmployeeID
,FirstName
,LastName FROM Employee where EmployeeID
not in (SELECT EmployeeID FROM
EmployeeProjects)
03/23/2024 94
Distinct Operator (Remove Duplicated Values)
SELECT EmployeeID FROM EmployeeProjects
03/23/2024 95
Multiple select statement
select (select firstname from employee where EmployeeID=1) as firstname,(select
LastName from employee where EmployeeID=1) as LastName , salary
,(select sqrt(salary) from employee where EmployeeID=1) as sqrtsalary ,(select
salary * 0.15 from employee where EmployeeID=1) as '10%salary'
from employee where EmployeeID=1
03/23/2024 96
Advance Topics to Learn
03/23/2024 97
Keep practice and
practice
Good
Luck