SlideShare a Scribd company logo
1 of 70
Structured Query Language
Introduction
 SQL is a standard language for storing,
manipulating and retrieving data in
database
 Same language can be used to query data
in MySQL, SQL Server, MS Access,
Oracle, Sybase, Informix, Postgres, and
other database systems
Data, Datasets And Database
Data
• Data are observations or
measurements
(unprocessed or
processed) represented as
text, numbers, or
multimedia
• Example: Details of
employees like Name, Age,
Town, etc. written
Dataset
• A dataset is a structured
collection of data generally
associated with a unique
body of work
• Example: Details of
employees of one town
organized alphabetically
Database
• A database is an organized
collection of data stored as
multiple datasets
• Example: Alphabetically
arranged details of all the
employees from all the
towns, stored in an
electronic unit
Understanding
Database  A database is an organized collection of
information or data
 A database is stored in an electronic storage
 Databases makes management of data easy
Relational
Database
 Stores data in form of tables
 Tables can be connected or related to each
other based on common data
 Supports SQL for querying
Structured
Query
Language
(SQL)
 SQL is a language that allows data from
database to be easily accessed,
manipulated, and updated
Date Fetching Process
Database
API Web Access
Any Program
SQL
Commands
DDL – Data Definition Language
DML – Data Manipulation Language
DCL – Data Control Language
TCL – Transaction Control Language
DQL- Data Query Language
DDL
CREATE ALTER DROP
DATABASE
Objects
Commands TRUNCATE
TABLE VIEW
DML
DELETE
Commands INSERT UPDATE
DCL
Commands GRANT REVOKE
TCL
SAVEPOINT
Commands
COMMIT ROLLBACK
DQL
Commands
SELECT
Structured Query Language
TABLES
Tables in SQL
 Created by CREATE TABLE statement
 CREATE TABLE Persons
PersonID FirstName LastName City Country
Numeric
Text
Text
Text
Text
Tables in SQL
Continues…
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
)
CREATE TABLE Persons(
PersonID int,
FirstName varchar(255),
LastName varchar(255),
City varchar(255),
Country varchar(255)
)
Tables in SQL
Continues…
 Key/entity/referential integrity constraints
 Can be specified in CREATE TABLE
 Can be added later using ALTER TABLE
 Table can be deleted by DROP TABLE
statement
Structured Query Language
CONSTRAINTS
Constraints
 NOT NULL
UNIQUE
PRIMARY KEY - NUT NULL + UNIQUE
FOREIGN KEY
CHECK
DEFAULT
CREATE INDEX
NOT NULL Constraint
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255) NOT NULL,
Age int
)
UNIQUE Constraint
CREATE TABLE Persons (
ID int NOT NULL UNIQUE,
LastName
varchar(255) NOT NULL,
FirstName varchar(255),
Age int
)
ID
11
12
13
14
ID
11
12
11
13
PRIMARY KEY Constraint
CREATE TABLE Persons (
ID int PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
)
PersonID FirstName LastNam
e
City Count
ry
P1 Will Kendy NYC US
P2 Mike Lauren NJ US
P3 Will Kendy Edison US
FOREIGN KEY Constraint
CREATE TABLE Orders (
OrderID
int NOT NULL PRIMARY KEY,
OrderNumber int NOT NULL,
PersonID
int FOREIGN KEY REFERENCES
Persons(PersonID)
)
PersonID FirstName LastName City Country
OrderID InvoiceN
um
PersonID
Primary
Key
Primary
Key
Foreign
Key
CHECK Constraint
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int CHECK (Age>=18)
)
CREATE TABLE PersonsTest (
ID int NOT NULL primary key,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255),
CONSTRAINT CHK_Person CHECK (Age>=18 AND datalength(City)>3)
)
DEFAULT Constraint
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255) DEFAULT 'Sandnes'
);
CREATE INDEX Statement
CREATE INDEX index_name
ON table_name (column1, column2, ...)
CREATE UNIQUE INDEX index_name
ON table_name (column1, column2, ...)
CREATE INDEX idx_lastname
ON Persons (LastName)
Structured Query Language
DATA TYPES
Data Types (String)
Data Type Description Max Size Storage
char(n) Fixed width character string 8,000 characters Defined width
varchar(n) Variable width character string 8,000 characters 2 bytes + number of chars
varchar(max) Variable width character string 1,073,741,824 characters 2 bytes + number of chars
text Variable width character string 2GB of text data 4 bytes + number of chars
nchar Fixed width Unicode string 4,000 characters Defined width x 2
nvarchar Variable width Unicode string 4,000 characters
nvarchar(max) Variable width Unicode string 536,870,912 characters
ntext Variable width Unicode string 2GB of text data
binary(n) Fixed width binary string 8,000 bytes
varbinary Variable width binary string 8,000 bytes
varbinary(max) Variable width binary string 2GB
image Variable width binary string 2GB
Numeric Data Types
Data type Description Storage
bit Integer that can be 0, 1, or NULL
tinyint Allows whole numbers from 0 to 255 1 byte
smallint Allows whole numbers between -32,768 and
32,767
2 bytes
int Allows whole numbers between -2,147,483,648
and 2,147,483,647
4 bytes
bigint Allows whole numbers between -
9,223,372,036,854,775,808 and
9,223,372,036,854,775,807
8 bytes
decimal(p,s) Fixed precision and scale numbers.
Allows numbers from -10^38 +1 to 10^38 –1.
The p parameter indicates precision. p must be a
value from 1 to 38. Default is 18.
The s parameter indicates scale. s must be a value
from 0 to p. Default value is 0
5-17 bytes
numeric(p,s) Fixed precision and scale numbers.
Allows numbers from -10^38 +1 to
10^38 –1.
The p parameter indicates precision. p
must be a value from 1 to 38. Default is
18.
The s parameter indicates scale. s must
be a value from 0 to p. Default value is 0
5-17 bytes
smallmoney Monetary data from -214,748.3648 to
214,748.3647
4 bytes
money Monetary data from -
922,337,203,685,477.5808 to
922,337,203,685,477.5807
8 bytes
float(n) Floating precision number data from -
1.79E + 308 to 1.79E + 308.
The n parameter indicates whether the
field should hold 4 or 8 bytes. float(24)
holds a 4-byte field and float(53) holds
an 8-byte field. Default value of n is 53.
4 or 8 bytes
real Floating precision number data from -
3.40E + 38 to 3.40E + 38
4 bytes
Date and Time Data Types
Data type Description Storage
datetime From January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds 8 bytes
datetime2 From January 1, 0001 to December 31, 9999 with an accuracy of 100 nanoseconds 6-8 bytes
smalldatetime From January 1, 1900 to June 6, 2079 with an accuracy of 1 minute 4 bytes
date Store a date only. From January 1, 0001 to December 31, 9999 3 bytes
time Store a time only to an accuracy of 100 nanoseconds 3-5 bytes
datetimeoffset The same as datetime2 with the addition of a time zone offset 8-10 bytes
timestamp Stores a unique number that gets updated every time a row gets created or modified. The
timestamp value is based upon an internal clock and does not correspond to real time.
Each table may have only one timestamp variable
Select Query
SELECT * FROM table_name
SELECT column1, column2, ...
FROM table_name
Select Query With Where Clause
SELECT column1, column2, ...
FROM table_name
WHERE condition
Example :
SELECT * FROM Customers
Where City='Boston’
SELECT * FROM Customers
WHERE ID=1
Select Query With Where Clause
Operator Description Example
= Equal City='Boston’
> Greater than [Shipping Fee]>100
< Less than [Shipping Fee]<100
>= Greater than or equal [Shipping Fee]>=100
<= Less than or equal [Shipping Fee]<=100
<> Not equal City<>'Boston’
Select Query With Order By
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC
SELECT * FROM Customers
ORDER BY City
ASCENDING is the default order
Select Query With DISTINCT
SELECT DISTINCT column1, column2, ...
FROM table_name;
SELECT distinct City FROM Customers
AND, OR and NOT Operators
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
Predicates
Predicate Description Example
BETWEEN Between a certain range Price BETWEEN 50 AND 60
LIKE Search for a pattern City LIKE 's%'
IN To specify multiple possible values
for a column
City IN ('Paris','London')
IS NULL If Selected column has blank rows Address IS NULL
IS NOT NULL IF the row is not blank in that
column
Address IS NOT NULL
Aliases
SELECT CustomerID AS ID, CustomerName AS Customer
FROM Customers
SELECT [first name] + ',' + [Last name] as CustName
From Customers
SELECT o.[Order ID], o.[Order Date], c.[First Name]FROM
Customers AS c, Orders AS o
WHERE c.City like 'L%'
Aggregate Functions
SELECT FUNCTION(column_name), column1, Column2…..
FROM table_name
WHERE condition
GROUP BY(column1, column2)
Functions:
• MAX()
• MIN()
• COUNT()
• SUM()
• AVG()
• FIRST()
• LAST()
Super Aggregate Functions
• ROLLUP
• COALESCE
Select [Ship City], coalesce([ship name],'Total') as Ship, sum([shipping fee])
From Orders
group by rollup([Ship City],[Ship Name])
SCALAR Functions
SELECT FUNCTION(column_name)
FROM table_name
WHERE condition
Functions:
• LOWER()
• UPPER()
• LEN()
• MID(column_name, Start, Length)
• ROUND(column_name, Decimals)
• GETDATE()
• FORMAT()
Group By
Group By :-
Used with Aggregate Functions, to group the result set
Syntax: Example:
SELECT column_name(s) Select [Ship City], avg([shipping fee])
FROM table_name from Orders
WHERE condition Group By [Ship City]
GROUP BY column_name(s)
ORDER BY column_name(s);
Having Clause
Having:-
Just as Where clause, “Having” works as condition for aggregated result
Syntax: Example:
SELECT column_name(s) Select [Ship City], avg([shipping fee])
FROM table_name from Orders
WHERE condition Group By [Ship City]
GROUP BY column_name(s) having avg([Shipping fee]) >100
HAVING condition
ORDER BY column_name(s);
Over(Partition By…)
A step forward from Group By, this function is used to portion a results set according to specified
criteria.
Select [Ship Country/Region],[Ship City],
avg([shipping fee]) over (partition by [ship city]) as Fee
from Orders
Ranking Functions
SELECT column1, Column2…. , FUNCTION Over(Order BY Column)
FROM table_name
Functions:
• Row_Number()
• Rank()
• Dense_Rank()
• NTILE(n)
Select [first name]+ ' ' + [last name] as EmpName, salary , Region, ntile(4)
over(partition by region order by salary desc) as Rnk
from employee
JOINS
DELETE
Commands INSERT UPDATE
A JOIN clause is used to combine rows from two or more tables, based on a related column between them
UNION, INTERSECT, EXCEPT
Union =
Intersect =
Except =
Views
Named Query
Advantages
Security
Simplicity
Consistency
Creating Views
CREATE/ALTER VIEW <View Name>
AS
<Query>
Select * from <View Name>
Encryption & SchemaBinding
CREATE VIEW <View Name>
WITH ENCRYPTION
AS
<Query>
• SCHEMABINDING
Complex Views
Indexing
CREATE
UNIQUE
CLUSTERED
INDEX
CREATE
NONCLUST
ERED
INDEX
Indexes
 Clustered Index
 Non-Clustered Index
 Only one Clustered index in a table
A table can have one or more non-clustered indexes and each non-clustered
index may include one or more columns of the table
Create Index
 CREATE CLUSTERED/NONCLUSTERED INDEX index_name
ON schema_name.table_name (column_list)
 NONCLUSTERED is the default index
Both Clustered & Non-Clustered Index can be made UNIQUE
Sub Query
One Query nested inside another
Statements can be SELECT, UPDATE,INSERT or
DELETE
Subqueries can be nested
Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name <OPERATOR>
(SELECT column_name FROM table_name WHERE condition)
Sub Query
Keywords
In place of an
expression
With IN or NOT
IN
With ANY or ALL
With EXISTS or
NOT EXISTS
In UPDATE,
DELETE, or
INSERT statement
In the FROM
clause
JOINS
JOINS
OUTER
Left Right Full
INNER
Theta Equi Natural
CROSS SELF
OUTER JOIN
Left Outer Join (A B)
OUTER JOIN
Right Outer Join (A B)
OUTER JOIN
Full Outer Join (A B)
INNER JOIN-Theta
INNER JOIN - EQUI
INNER JOIN - Natural
CROSS JOIN
Table 1
Col A
1
2
Table 2
Col B
3
2
4
Answer
Col A Col B
1 3
1 2
1 4
2 3
2 2
2 4
SELF JOIN
 Join a table to itself
 Works with INNER JOIN or LEFT OUTER JOIN
Structured Query Language
Defining Roles
ROLES
 To easily manage the permissions in your databases, SQL Server provides
several roles which are security principals that group other principals. They are
like groups in the Microsoft Windows operating system
 There are two types of roles
- Server Level
- Application Level
Server Roles
 Sysadmin -if a login is a member of this role, it can do anything within the SQL Server
 Bulkadmin -This role allows the import of data from external files
 Dbcreator - This role allows creation of databases within SQL Server
 Diskadmin - This role allows management of backup devices, which aren't used very much in SQL Server any
more
 Processadmin - This is a powerful role because it can kill connections to SQL Server. Should be used rarely
 Securityadmin- This role controls logins for SQL Server
 Serveradmin - This role manages the SQL Server configuration
 Setupadmin - Setup admin basically gives control over linked servers
An Important Query - Find Duplicates
SELECT
col1,col2,...
COUNT(*)
FROM
table_name
GROUP BY
col1,col2,...
HAVING
COUNT(*) > 1
Want to move to Advanced SQL/ Any Customized
Topics of SQL or Any other Training
Connect at:
partner@edu4sure.com
+91-95.5511.5533
edu4sure.com/certificate-courses

More Related Content

What's hot

Physical elements of data
Physical elements of dataPhysical elements of data
Physical elements of dataDimara Hakim
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLPrashant Kumar
 
Sql tables
Sql tablesSql tables
Sql tablesRanidm
 
Covering indexes
Covering indexesCovering indexes
Covering indexesMYXPLAIN
 
Intro to tsql unit 7
Intro to tsql   unit 7Intro to tsql   unit 7
Intro to tsql unit 7Syed Asrarali
 
Learning sql from w3schools
Learning sql from w3schoolsLearning sql from w3schools
Learning sql from w3schoolsfarhan516
 
Using ddl statements to create and manage tables
Using ddl statements to create and manage tablesUsing ddl statements to create and manage tables
Using ddl statements to create and manage tablesSyed Zaid Irshad
 

What's hot (17)

Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
Physical elements of data
Physical elements of dataPhysical elements of data
Physical elements of data
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
Sql intro
Sql introSql intro
Sql intro
 
Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
 
Sql tables
Sql tablesSql tables
Sql tables
 
2.0 sql data types for my sql, sql server
2.0 sql data types for my sql, sql server2.0 sql data types for my sql, sql server
2.0 sql data types for my sql, sql server
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 
Covering indexes
Covering indexesCovering indexes
Covering indexes
 
Sql
SqlSql
Sql
 
SImple SQL
SImple SQLSImple SQL
SImple SQL
 
Intro to tsql unit 7
Intro to tsql   unit 7Intro to tsql   unit 7
Intro to tsql unit 7
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Learning sql from w3schools
Learning sql from w3schoolsLearning sql from w3schools
Learning sql from w3schools
 
Using ddl statements to create and manage tables
Using ddl statements to create and manage tablesUsing ddl statements to create and manage tables
Using ddl statements to create and manage tables
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 

Similar to SQL (Basic to Intermediate Customized 8 Hours)

Intro to tsql unit 5
Intro to tsql   unit 5Intro to tsql   unit 5
Intro to tsql unit 5Syed Asrarali
 
Structured Query Language (SQL) _ Edu4Sure Training.pptx
Structured Query Language (SQL) _ Edu4Sure Training.pptxStructured Query Language (SQL) _ Edu4Sure Training.pptx
Structured Query Language (SQL) _ Edu4Sure Training.pptxEdu4Sure
 
SQL Commands Part 1.pptx
SQL Commands Part 1.pptxSQL Commands Part 1.pptx
SQL Commands Part 1.pptxRUBAB79
 
Sql data types for various d bs by naveen kumar veligeti
Sql data types for various d bs by naveen kumar veligetiSql data types for various d bs by naveen kumar veligeti
Sql data types for various d bs by naveen kumar veligetiNaveen Kumar Veligeti
 
Tugas basis data 2012110028
Tugas basis data 2012110028Tugas basis data 2012110028
Tugas basis data 2012110028UIGM
 
2018 02 20_biological_databases_part2_v_upload
2018 02 20_biological_databases_part2_v_upload2018 02 20_biological_databases_part2_v_upload
2018 02 20_biological_databases_part2_v_uploadProf. Wim Van Criekinge
 
Simple Queriebhjjnhhbbbbnnnnjjs In SQL.pdf
Simple Queriebhjjnhhbbbbnnnnjjs In SQL.pdfSimple Queriebhjjnhhbbbbnnnnjjs In SQL.pdf
Simple Queriebhjjnhhbbbbnnnnjjs In SQL.pdfManojVishwakarma91
 
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB plc
 
Postgresql 9.3 overview
Postgresql 9.3 overviewPostgresql 9.3 overview
Postgresql 9.3 overviewAveic
 

Similar to SQL (Basic to Intermediate Customized 8 Hours) (20)

unit 1 ppt.pptx
unit 1 ppt.pptxunit 1 ppt.pptx
unit 1 ppt.pptx
 
Intro to tsql unit 5
Intro to tsql   unit 5Intro to tsql   unit 5
Intro to tsql unit 5
 
Structured Query Language (SQL) _ Edu4Sure Training.pptx
Structured Query Language (SQL) _ Edu4Sure Training.pptxStructured Query Language (SQL) _ Edu4Sure Training.pptx
Structured Query Language (SQL) _ Edu4Sure Training.pptx
 
DBMS
DBMSDBMS
DBMS
 
2016 02 23_biological_databases_part2
2016 02 23_biological_databases_part22016 02 23_biological_databases_part2
2016 02 23_biological_databases_part2
 
2017 biological databasespart2
2017 biological databasespart22017 biological databasespart2
2017 biological databasespart2
 
GPREC DBMS Notes 1
GPREC DBMS Notes 1GPREC DBMS Notes 1
GPREC DBMS Notes 1
 
SQL Commands Part 1.pptx
SQL Commands Part 1.pptxSQL Commands Part 1.pptx
SQL Commands Part 1.pptx
 
Sql data types for various d bs by naveen kumar veligeti
Sql data types for various d bs by naveen kumar veligetiSql data types for various d bs by naveen kumar veligeti
Sql data types for various d bs by naveen kumar veligeti
 
Sql tables
Sql tablesSql tables
Sql tables
 
Tugas basis data 2012110028
Tugas basis data 2012110028Tugas basis data 2012110028
Tugas basis data 2012110028
 
Database Sizing
Database SizingDatabase Sizing
Database Sizing
 
2018 02 20_biological_databases_part2_v_upload
2018 02 20_biological_databases_part2_v_upload2018 02 20_biological_databases_part2_v_upload
2018 02 20_biological_databases_part2_v_upload
 
Sql server lab_2
Sql server lab_2Sql server lab_2
Sql server lab_2
 
Simple Queriebhjjnhhbbbbnnnnjjs In SQL.pdf
Simple Queriebhjjnhhbbbbnnnnjjs In SQL.pdfSimple Queriebhjjnhhbbbbnnnnjjs In SQL.pdf
Simple Queriebhjjnhhbbbbnnnnjjs In SQL.pdf
 
Sql
SqlSql
Sql
 
Less08 Schema
Less08 SchemaLess08 Schema
Less08 Schema
 
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
 
MSAvMySQL.pptx
MSAvMySQL.pptxMSAvMySQL.pptx
MSAvMySQL.pptx
 
Postgresql 9.3 overview
Postgresql 9.3 overviewPostgresql 9.3 overview
Postgresql 9.3 overview
 

More from Edu4Sure

Market Research using SPSS _ Edu4Sure Sept 2023.ppt
Market Research using SPSS _ Edu4Sure Sept 2023.pptMarket Research using SPSS _ Edu4Sure Sept 2023.ppt
Market Research using SPSS _ Edu4Sure Sept 2023.pptEdu4Sure
 
Sales Training 2023.pptx
Sales Training 2023.pptxSales Training 2023.pptx
Sales Training 2023.pptxEdu4Sure
 
Seo tips continue 1 to 1 live
Seo tips continue 1 to 1 liveSeo tips continue 1 to 1 live
Seo tips continue 1 to 1 liveEdu4Sure
 
Marketing concepts
Marketing conceptsMarketing concepts
Marketing conceptsEdu4Sure
 
Edu4Sure - Entrepreneurship
Edu4Sure - EntrepreneurshipEdu4Sure - Entrepreneurship
Edu4Sure - EntrepreneurshipEdu4Sure
 
Edu4Sure - Instagram
Edu4Sure - InstagramEdu4Sure - Instagram
Edu4Sure - InstagramEdu4Sure
 
Edu4Sure - Affiliate Marketing
Edu4Sure - Affiliate MarketingEdu4Sure - Affiliate Marketing
Edu4Sure - Affiliate MarketingEdu4Sure
 
Edu4Sure - YouTube
Edu4Sure - YouTubeEdu4Sure - YouTube
Edu4Sure - YouTubeEdu4Sure
 
Edu4Sure - Web Analytics (Google)
Edu4Sure - Web Analytics (Google)Edu4Sure - Web Analytics (Google)
Edu4Sure - Web Analytics (Google)Edu4Sure
 
Edu4Sure - Google AdSense
Edu4Sure - Google AdSenseEdu4Sure - Google AdSense
Edu4Sure - Google AdSenseEdu4Sure
 
Edu4Sure - Power BI (MS Analytics Tool)
Edu4Sure - Power BI (MS Analytics Tool)Edu4Sure - Power BI (MS Analytics Tool)
Edu4Sure - Power BI (MS Analytics Tool)Edu4Sure
 
Edu4Sure - WordPress
Edu4Sure - WordPressEdu4Sure - WordPress
Edu4Sure - WordPressEdu4Sure
 
Edu4Sure - Google Ads Mistakes
Edu4Sure - Google Ads MistakesEdu4Sure - Google Ads Mistakes
Edu4Sure - Google Ads MistakesEdu4Sure
 
Edu4Sure - LinkedIn
Edu4Sure - LinkedInEdu4Sure - LinkedIn
Edu4Sure - LinkedInEdu4Sure
 
Edu4Sure - Social Media Marketing Powerfil Month Tips
Edu4Sure - Social Media Marketing Powerfil Month TipsEdu4Sure - Social Media Marketing Powerfil Month Tips
Edu4Sure - Social Media Marketing Powerfil Month TipsEdu4Sure
 
Edu4Sure - eMail Marketing (Mailchimp)
Edu4Sure - eMail Marketing (Mailchimp)Edu4Sure - eMail Marketing (Mailchimp)
Edu4Sure - eMail Marketing (Mailchimp)Edu4Sure
 
Edu4Sure - Google Ads Fundamentals
Edu4Sure - Google Ads FundamentalsEdu4Sure - Google Ads Fundamentals
Edu4Sure - Google Ads FundamentalsEdu4Sure
 
Edu4Sure - SEO SMO SMM
Edu4Sure - SEO SMO SMMEdu4Sure - SEO SMO SMM
Edu4Sure - SEO SMO SMMEdu4Sure
 
Edu4Sure - Quora
Edu4Sure - QuoraEdu4Sure - Quora
Edu4Sure - QuoraEdu4Sure
 
Edu4Sure - Google AdWords / PPC
Edu4Sure - Google AdWords / PPCEdu4Sure - Google AdWords / PPC
Edu4Sure - Google AdWords / PPCEdu4Sure
 

More from Edu4Sure (20)

Market Research using SPSS _ Edu4Sure Sept 2023.ppt
Market Research using SPSS _ Edu4Sure Sept 2023.pptMarket Research using SPSS _ Edu4Sure Sept 2023.ppt
Market Research using SPSS _ Edu4Sure Sept 2023.ppt
 
Sales Training 2023.pptx
Sales Training 2023.pptxSales Training 2023.pptx
Sales Training 2023.pptx
 
Seo tips continue 1 to 1 live
Seo tips continue 1 to 1 liveSeo tips continue 1 to 1 live
Seo tips continue 1 to 1 live
 
Marketing concepts
Marketing conceptsMarketing concepts
Marketing concepts
 
Edu4Sure - Entrepreneurship
Edu4Sure - EntrepreneurshipEdu4Sure - Entrepreneurship
Edu4Sure - Entrepreneurship
 
Edu4Sure - Instagram
Edu4Sure - InstagramEdu4Sure - Instagram
Edu4Sure - Instagram
 
Edu4Sure - Affiliate Marketing
Edu4Sure - Affiliate MarketingEdu4Sure - Affiliate Marketing
Edu4Sure - Affiliate Marketing
 
Edu4Sure - YouTube
Edu4Sure - YouTubeEdu4Sure - YouTube
Edu4Sure - YouTube
 
Edu4Sure - Web Analytics (Google)
Edu4Sure - Web Analytics (Google)Edu4Sure - Web Analytics (Google)
Edu4Sure - Web Analytics (Google)
 
Edu4Sure - Google AdSense
Edu4Sure - Google AdSenseEdu4Sure - Google AdSense
Edu4Sure - Google AdSense
 
Edu4Sure - Power BI (MS Analytics Tool)
Edu4Sure - Power BI (MS Analytics Tool)Edu4Sure - Power BI (MS Analytics Tool)
Edu4Sure - Power BI (MS Analytics Tool)
 
Edu4Sure - WordPress
Edu4Sure - WordPressEdu4Sure - WordPress
Edu4Sure - WordPress
 
Edu4Sure - Google Ads Mistakes
Edu4Sure - Google Ads MistakesEdu4Sure - Google Ads Mistakes
Edu4Sure - Google Ads Mistakes
 
Edu4Sure - LinkedIn
Edu4Sure - LinkedInEdu4Sure - LinkedIn
Edu4Sure - LinkedIn
 
Edu4Sure - Social Media Marketing Powerfil Month Tips
Edu4Sure - Social Media Marketing Powerfil Month TipsEdu4Sure - Social Media Marketing Powerfil Month Tips
Edu4Sure - Social Media Marketing Powerfil Month Tips
 
Edu4Sure - eMail Marketing (Mailchimp)
Edu4Sure - eMail Marketing (Mailchimp)Edu4Sure - eMail Marketing (Mailchimp)
Edu4Sure - eMail Marketing (Mailchimp)
 
Edu4Sure - Google Ads Fundamentals
Edu4Sure - Google Ads FundamentalsEdu4Sure - Google Ads Fundamentals
Edu4Sure - Google Ads Fundamentals
 
Edu4Sure - SEO SMO SMM
Edu4Sure - SEO SMO SMMEdu4Sure - SEO SMO SMM
Edu4Sure - SEO SMO SMM
 
Edu4Sure - Quora
Edu4Sure - QuoraEdu4Sure - Quora
Edu4Sure - Quora
 
Edu4Sure - Google AdWords / PPC
Edu4Sure - Google AdWords / PPCEdu4Sure - Google AdWords / PPC
Edu4Sure - Google AdWords / PPC
 

Recently uploaded

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 

Recently uploaded (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

SQL (Basic to Intermediate Customized 8 Hours)

  • 2. Introduction  SQL is a standard language for storing, manipulating and retrieving data in database  Same language can be used to query data in MySQL, SQL Server, MS Access, Oracle, Sybase, Informix, Postgres, and other database systems
  • 3. Data, Datasets And Database Data • Data are observations or measurements (unprocessed or processed) represented as text, numbers, or multimedia • Example: Details of employees like Name, Age, Town, etc. written Dataset • A dataset is a structured collection of data generally associated with a unique body of work • Example: Details of employees of one town organized alphabetically Database • A database is an organized collection of data stored as multiple datasets • Example: Alphabetically arranged details of all the employees from all the towns, stored in an electronic unit
  • 4. Understanding Database  A database is an organized collection of information or data  A database is stored in an electronic storage  Databases makes management of data easy
  • 5. Relational Database  Stores data in form of tables  Tables can be connected or related to each other based on common data  Supports SQL for querying
  • 6. Structured Query Language (SQL)  SQL is a language that allows data from database to be easily accessed, manipulated, and updated
  • 7. Date Fetching Process Database API Web Access Any Program
  • 8. SQL Commands DDL – Data Definition Language DML – Data Manipulation Language DCL – Data Control Language TCL – Transaction Control Language DQL- Data Query Language
  • 15. Tables in SQL  Created by CREATE TABLE statement  CREATE TABLE Persons PersonID FirstName LastName City Country Numeric Text Text Text Text
  • 16. Tables in SQL Continues… CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... ) CREATE TABLE Persons( PersonID int, FirstName varchar(255), LastName varchar(255), City varchar(255), Country varchar(255) )
  • 17. Tables in SQL Continues…  Key/entity/referential integrity constraints  Can be specified in CREATE TABLE  Can be added later using ALTER TABLE  Table can be deleted by DROP TABLE statement
  • 19. Constraints  NOT NULL UNIQUE PRIMARY KEY - NUT NULL + UNIQUE FOREIGN KEY CHECK DEFAULT CREATE INDEX
  • 20. NOT NULL Constraint CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255) NOT NULL, Age int )
  • 21. UNIQUE Constraint CREATE TABLE Persons ( ID int NOT NULL UNIQUE, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int ) ID 11 12 13 14 ID 11 12 11 13
  • 22. PRIMARY KEY Constraint CREATE TABLE Persons ( ID int PRIMARY KEY, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int ) PersonID FirstName LastNam e City Count ry P1 Will Kendy NYC US P2 Mike Lauren NJ US P3 Will Kendy Edison US
  • 23. FOREIGN KEY Constraint CREATE TABLE Orders ( OrderID int NOT NULL PRIMARY KEY, OrderNumber int NOT NULL, PersonID int FOREIGN KEY REFERENCES Persons(PersonID) ) PersonID FirstName LastName City Country OrderID InvoiceN um PersonID Primary Key Primary Key Foreign Key
  • 24. CHECK Constraint CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int CHECK (Age>=18) ) CREATE TABLE PersonsTest ( ID int NOT NULL primary key, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, City varchar(255), CONSTRAINT CHK_Person CHECK (Age>=18 AND datalength(City)>3) )
  • 25. DEFAULT Constraint CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, City varchar(255) DEFAULT 'Sandnes' );
  • 26. CREATE INDEX Statement CREATE INDEX index_name ON table_name (column1, column2, ...) CREATE UNIQUE INDEX index_name ON table_name (column1, column2, ...) CREATE INDEX idx_lastname ON Persons (LastName)
  • 28. Data Types (String) Data Type Description Max Size Storage char(n) Fixed width character string 8,000 characters Defined width varchar(n) Variable width character string 8,000 characters 2 bytes + number of chars varchar(max) Variable width character string 1,073,741,824 characters 2 bytes + number of chars text Variable width character string 2GB of text data 4 bytes + number of chars nchar Fixed width Unicode string 4,000 characters Defined width x 2 nvarchar Variable width Unicode string 4,000 characters nvarchar(max) Variable width Unicode string 536,870,912 characters ntext Variable width Unicode string 2GB of text data binary(n) Fixed width binary string 8,000 bytes varbinary Variable width binary string 8,000 bytes varbinary(max) Variable width binary string 2GB image Variable width binary string 2GB
  • 29. Numeric Data Types Data type Description Storage bit Integer that can be 0, 1, or NULL tinyint Allows whole numbers from 0 to 255 1 byte smallint Allows whole numbers between -32,768 and 32,767 2 bytes int Allows whole numbers between -2,147,483,648 and 2,147,483,647 4 bytes bigint Allows whole numbers between - 9,223,372,036,854,775,808 and 9,223,372,036,854,775,807 8 bytes decimal(p,s) Fixed precision and scale numbers. Allows numbers from -10^38 +1 to 10^38 –1. The p parameter indicates precision. p must be a value from 1 to 38. Default is 18. The s parameter indicates scale. s must be a value from 0 to p. Default value is 0 5-17 bytes numeric(p,s) Fixed precision and scale numbers. Allows numbers from -10^38 +1 to 10^38 –1. The p parameter indicates precision. p must be a value from 1 to 38. Default is 18. The s parameter indicates scale. s must be a value from 0 to p. Default value is 0 5-17 bytes smallmoney Monetary data from -214,748.3648 to 214,748.3647 4 bytes money Monetary data from - 922,337,203,685,477.5808 to 922,337,203,685,477.5807 8 bytes float(n) Floating precision number data from - 1.79E + 308 to 1.79E + 308. The n parameter indicates whether the field should hold 4 or 8 bytes. float(24) holds a 4-byte field and float(53) holds an 8-byte field. Default value of n is 53. 4 or 8 bytes real Floating precision number data from - 3.40E + 38 to 3.40E + 38 4 bytes
  • 30. Date and Time Data Types Data type Description Storage datetime From January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds 8 bytes datetime2 From January 1, 0001 to December 31, 9999 with an accuracy of 100 nanoseconds 6-8 bytes smalldatetime From January 1, 1900 to June 6, 2079 with an accuracy of 1 minute 4 bytes date Store a date only. From January 1, 0001 to December 31, 9999 3 bytes time Store a time only to an accuracy of 100 nanoseconds 3-5 bytes datetimeoffset The same as datetime2 with the addition of a time zone offset 8-10 bytes timestamp Stores a unique number that gets updated every time a row gets created or modified. The timestamp value is based upon an internal clock and does not correspond to real time. Each table may have only one timestamp variable
  • 31. Select Query SELECT * FROM table_name SELECT column1, column2, ... FROM table_name
  • 32. Select Query With Where Clause SELECT column1, column2, ... FROM table_name WHERE condition Example : SELECT * FROM Customers Where City='Boston’ SELECT * FROM Customers WHERE ID=1
  • 33. Select Query With Where Clause Operator Description Example = Equal City='Boston’ > Greater than [Shipping Fee]>100 < Less than [Shipping Fee]<100 >= Greater than or equal [Shipping Fee]>=100 <= Less than or equal [Shipping Fee]<=100 <> Not equal City<>'Boston’
  • 34. Select Query With Order By SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC SELECT * FROM Customers ORDER BY City ASCENDING is the default order
  • 35. Select Query With DISTINCT SELECT DISTINCT column1, column2, ... FROM table_name; SELECT distinct City FROM Customers
  • 36. AND, OR and NOT Operators SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 AND condition3 ... SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR condition3 ... SELECT column1, column2, ... FROM table_name WHERE NOT condition;
  • 37. Predicates Predicate Description Example BETWEEN Between a certain range Price BETWEEN 50 AND 60 LIKE Search for a pattern City LIKE 's%' IN To specify multiple possible values for a column City IN ('Paris','London') IS NULL If Selected column has blank rows Address IS NULL IS NOT NULL IF the row is not blank in that column Address IS NOT NULL
  • 38. Aliases SELECT CustomerID AS ID, CustomerName AS Customer FROM Customers SELECT [first name] + ',' + [Last name] as CustName From Customers SELECT o.[Order ID], o.[Order Date], c.[First Name]FROM Customers AS c, Orders AS o WHERE c.City like 'L%'
  • 39. Aggregate Functions SELECT FUNCTION(column_name), column1, Column2….. FROM table_name WHERE condition GROUP BY(column1, column2) Functions: • MAX() • MIN() • COUNT() • SUM() • AVG() • FIRST() • LAST()
  • 40. Super Aggregate Functions • ROLLUP • COALESCE Select [Ship City], coalesce([ship name],'Total') as Ship, sum([shipping fee]) From Orders group by rollup([Ship City],[Ship Name])
  • 41. SCALAR Functions SELECT FUNCTION(column_name) FROM table_name WHERE condition Functions: • LOWER() • UPPER() • LEN() • MID(column_name, Start, Length) • ROUND(column_name, Decimals) • GETDATE() • FORMAT()
  • 42. Group By Group By :- Used with Aggregate Functions, to group the result set Syntax: Example: SELECT column_name(s) Select [Ship City], avg([shipping fee]) FROM table_name from Orders WHERE condition Group By [Ship City] GROUP BY column_name(s) ORDER BY column_name(s);
  • 43. Having Clause Having:- Just as Where clause, “Having” works as condition for aggregated result Syntax: Example: SELECT column_name(s) Select [Ship City], avg([shipping fee]) FROM table_name from Orders WHERE condition Group By [Ship City] GROUP BY column_name(s) having avg([Shipping fee]) >100 HAVING condition ORDER BY column_name(s);
  • 44. Over(Partition By…) A step forward from Group By, this function is used to portion a results set according to specified criteria. Select [Ship Country/Region],[Ship City], avg([shipping fee]) over (partition by [ship city]) as Fee from Orders
  • 45. Ranking Functions SELECT column1, Column2…. , FUNCTION Over(Order BY Column) FROM table_name Functions: • Row_Number() • Rank() • Dense_Rank() • NTILE(n) Select [first name]+ ' ' + [last name] as EmpName, salary , Region, ntile(4) over(partition by region order by salary desc) as Rnk from employee
  • 46. JOINS DELETE Commands INSERT UPDATE A JOIN clause is used to combine rows from two or more tables, based on a related column between them
  • 47. UNION, INTERSECT, EXCEPT Union = Intersect = Except =
  • 49. Creating Views CREATE/ALTER VIEW <View Name> AS <Query> Select * from <View Name>
  • 50. Encryption & SchemaBinding CREATE VIEW <View Name> WITH ENCRYPTION AS <Query> • SCHEMABINDING
  • 52. Indexes  Clustered Index  Non-Clustered Index  Only one Clustered index in a table A table can have one or more non-clustered indexes and each non-clustered index may include one or more columns of the table
  • 53. Create Index  CREATE CLUSTERED/NONCLUSTERED INDEX index_name ON schema_name.table_name (column_list)  NONCLUSTERED is the default index Both Clustered & Non-Clustered Index can be made UNIQUE
  • 54. Sub Query One Query nested inside another Statements can be SELECT, UPDATE,INSERT or DELETE Subqueries can be nested
  • 55. Syntax SELECT column_name(s) FROM table_name WHERE column_name <OPERATOR> (SELECT column_name FROM table_name WHERE condition)
  • 56. Sub Query Keywords In place of an expression With IN or NOT IN With ANY or ALL With EXISTS or NOT EXISTS In UPDATE, DELETE, or INSERT statement In the FROM clause
  • 58. OUTER JOIN Left Outer Join (A B)
  • 60. OUTER JOIN Full Outer Join (A B)
  • 62. INNER JOIN - EQUI
  • 63. INNER JOIN - Natural
  • 64. CROSS JOIN Table 1 Col A 1 2 Table 2 Col B 3 2 4 Answer Col A Col B 1 3 1 2 1 4 2 3 2 2 2 4
  • 65. SELF JOIN  Join a table to itself  Works with INNER JOIN or LEFT OUTER JOIN
  • 67. ROLES  To easily manage the permissions in your databases, SQL Server provides several roles which are security principals that group other principals. They are like groups in the Microsoft Windows operating system  There are two types of roles - Server Level - Application Level
  • 68. Server Roles  Sysadmin -if a login is a member of this role, it can do anything within the SQL Server  Bulkadmin -This role allows the import of data from external files  Dbcreator - This role allows creation of databases within SQL Server  Diskadmin - This role allows management of backup devices, which aren't used very much in SQL Server any more  Processadmin - This is a powerful role because it can kill connections to SQL Server. Should be used rarely  Securityadmin- This role controls logins for SQL Server  Serveradmin - This role manages the SQL Server configuration  Setupadmin - Setup admin basically gives control over linked servers
  • 69. An Important Query - Find Duplicates SELECT col1,col2,... COUNT(*) FROM table_name GROUP BY col1,col2,... HAVING COUNT(*) > 1
  • 70. Want to move to Advanced SQL/ Any Customized Topics of SQL or Any other Training Connect at: partner@edu4sure.com +91-95.5511.5533 edu4sure.com/certificate-courses

Editor's Notes

  1. Most of the companies do not incentivize their employees on their ideas and not just efforts….