SlideShare a Scribd company logo
SQL LECTURE
HOW SQL WORKS
Inside the server
Objects in a database
Creating a table
Core SQL Commands
DCL Command(Not to be used by us)
Data Types
Datatype – Char(30) & Varchar
Char is better than Varchar in terms of processing speed but varchar is more memory efficient than char
Selection of data type
Need to understand all the data types to create a table with proper datatype for proper optimization
Summary
• Rest of the data types were explained which are available on LMS.
• Whenever you open the client for SQL you have to mention which
database you have to use within the server. Eg- use mydb (database name)
• Client s/w doesn’t store any data on it, its always stored on the server.
• WARNING- if you execute same command twice, it gets executed
multiple times and it might result in addition of unnecessary data.
• Values should be added in same exact order as table column name
‘NULL’ Datatype.
Null is not 0.
Null signifies unknown value.
Can be used only with ‘is not’ command.
DDL commands
• DDL command is Data Definition Language command, used to define
a type of dataset for table creation and modification of a table only
• ‘DR CAT’
• D - DROP
• R - RENAME
• C - CREATE
• A - ALTER
• T - TRUNCATE
Use and format of ALTER & RENAME
TRUNCATE command
• Truncate command deletes the entire Data or the Table content.
• It internally executes 2 commands
• Drops table entirely
• Create fresh table with similar column
• Truncate command cannot be rolled back.
• Truncate comment will delete all the objects created above the table.
DML commands
• DML command stands for Data Manipulation Language
• Used to manipulate data within the table
• It is used to modify the data within the table
• DML commands
• Insert – to insert data
• Update – to update existing data
• Delete – to delete the record in data.
Alternate way to use INSERT command
• When we don’t know the values of multiple data and want to put
NULL data type we can use the format to specify the data input.
‘Where’ clause in DML & DQL command
‘Update’ command
‘WHERE’ clause
• Where clause is used to define a condition in a query or specific record
• Type1- update students set sname = 'Thomas' where std_id = 1;
• Type2- update students set course = ‘analytics’, marks = 25 where
sname = ‘Thomas’
• Type3- update students set course = ‘ analytics’ (all change)
• For NULL- update students set marks = 0 where course is null
‘HAVING’ clause
• Having clause is used to select specific groups
‘Delete’ command
• Syntax is similar to ‘update’ command
• Delete from students where std_id = 1;
• Delete from students, (will delete all the table records)
DQL command – Select (will be used 85%*)
• Different ways to use select command
• Select * from myemp ; – shows everything
• Select count(*) from myemp ; – shows count of rows
• Select * from myemp limit 5 ; – limits data to 5 rows;
• Select first_name, last _name,salary from myemp limit 10 ;
Function of ‘SELECT’
• Select does not make any change in the backend.
• It just shows you the desired output
• Can help you make derived column(temp column)
• Select first_name, last _name,salary, salary*0.2 from myemp limit 10 ;
• We can use other arethmatic operators with ‘where’ clause.
• select * from myemp where salary >= 10000;
• select first_name,last_name,job_id,salary from myemp where salary >=
15000;
• IN,BETWEEN,LIKE operators also exist for convenience
Result table for AND & OR & IN operator
select * from myemp where dep_id in (20,40,60);
#use IN operator for multiple condition of same column
Pattern matching for LIKE operator
select * from myemp where first_name like 'j%'; #name starts with J
select * from myemp where first_name like '%a'; #name ends with A
Sorting the table – ‘ORDER BY’
• Order by clause is used ro sort the table according to particular
column
• Select * from myemp order by dep_id; - by default Ascending
• Select * from myemp order by dep_id desc;
Distinct function
• To find out unique values in a table
• Select distinct dep_id from myemp;
String functions & operators
• CONCAT()
• LEFT
• RIGHT()
• LOWER()
• UPPER()
https://dev.mysql.com/doc/refman/8.0/en/string-functions.html
Link for all string functions that can be used
Date & Time functions
• ADDDATE()
• ADDTIME()
• CURDATE()
• CURTIME()
• NOW()
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html
Link for all DATE functions that can be used
Group functions
• SUM()
• AVG()
• MIN()
• MAX()
• STD()
JOINS in mySQL
• INNER JOIN
• LEFT JOIN
• RIGHT JOIN
• CROSS JOIN
• SELF JOIN
• THE RESULTANT TABLE THAT WILL BE CREATED IS THE VIRTUAL TABLE
RESPECTIVE OF THE TYPE OF JOIN USED.
JOINS
INNER JOIN
LEFT Join
CROSS Join
• It is irrespective to the common record.
• Will join each record of left table to the corroponding each record of
the right table.
Using “PREFIX” and Alias Name
• Its efficient to use prefix to be desprictive
• Eg- select meals.mealname, drinks.drinkname
• Alias name can be used if we are going to use similar name name
multiple times in a table
• We can use alias name for large table names to reduce the size of the
query.
• Eg- select d.drinks, m.meals from drinks as d cross join meals as m;
SELF JOIN
Data Constraints
Command example
Concept of primary key
Relations between parent and child table
Create parent and Child Table
TCL - Transaction control language
Transaction-Except/Rollback/Savepoint/commit
• Transaction/except – turns off autocommit and executes data or
terminates.
• Rollback – works like undo. Will work only if autocommit is off.
• Savepoint – creates savepoint for rollback in between transaction.
• Commit- Commit the data typed. We cant rollback once commitment
is done.
Exception Handling
Exceptional Handeling Format
COMMIT & ROLLBACK
A.C.I.D rule
Views
Can be used on “select’ to create a virtual table to select particular paramaters
in a table but editing the view will also edit the main table
Hyperlink- All about Views
SEQUENCE object
• Mysql doesn’t have a feature of creating a sequence hence we have
to create a sequence implicitly.
• create table mytab (id integer primary key auto_increment,name
varchar (30),age integer);
INDEX
• Performance of the query is improved.
• Search and Retrieval of data becomes faster.
• Indexes youtube video
Stored Procedures
• Variables- Parameters & Local Variables
• Local variables – are the variabls that a re written and declared within
the procedure.
• Create a procedure in procedures tabs in schemas
• Stored Procedures is used to make a function
Parameters Local Variables
LOOPS
SQL LECTURE.pptx
SQL LECTURE.pptx
SQL LECTURE.pptx
SQL LECTURE.pptx
SQL LECTURE.pptx
SQL LECTURE.pptx
SQL LECTURE.pptx
SQL LECTURE.pptx

More Related Content

Similar to SQL LECTURE.pptx

SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
PriyaPandey767008
 
Practical 03 (1).pptx
Practical 03 (1).pptxPractical 03 (1).pptx
Practical 03 (1).pptx
solangiirfan92
 
PL_SQL - II.pptx
PL_SQL - II.pptxPL_SQL - II.pptx
PL_SQL - II.pptx
priyaprakash11
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
InfoRepos Technologies
 
OracleSQLraining.pptx
OracleSQLraining.pptxOracleSQLraining.pptx
OracleSQLraining.pptx
Rajendra Jain
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
Nick Buytaert
 
Mssql
MssqlMssql
Mssql
Janas Khan
 
Dbms
DbmsDbms
Dbms sql-final
Dbms  sql-finalDbms  sql-final
0808.pdf
0808.pdf0808.pdf
0808.pdf
ssuser0562f1
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
ssuser0562f1
 
SQL: Introduction and its Basic Commands
SQL: Introduction and its Basic CommandsSQL: Introduction and its Basic Commands
SQL: Introduction and its Basic Commands
niyantadesai7
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
Sharad Dubey
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
metsarin
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
MARasheed3
 
MySQL basics
MySQL basicsMySQL basics
MySQL basics
Jamshid Hashimi
 
SQL(NEW).pptx
SQL(NEW).pptxSQL(NEW).pptx
SQL(NEW).pptx
PoojaChawan2
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
TamiratDejene1
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
Md.Mojibul Hoque
 
Sql server
Sql serverSql server
Sql server
Fajar Baskoro
 

Similar to SQL LECTURE.pptx (20)

SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
Practical 03 (1).pptx
Practical 03 (1).pptxPractical 03 (1).pptx
Practical 03 (1).pptx
 
PL_SQL - II.pptx
PL_SQL - II.pptxPL_SQL - II.pptx
PL_SQL - II.pptx
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
OracleSQLraining.pptx
OracleSQLraining.pptxOracleSQLraining.pptx
OracleSQLraining.pptx
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
 
Mssql
MssqlMssql
Mssql
 
Dbms
DbmsDbms
Dbms
 
Dbms sql-final
Dbms  sql-finalDbms  sql-final
Dbms sql-final
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
SQL: Introduction and its Basic Commands
SQL: Introduction and its Basic CommandsSQL: Introduction and its Basic Commands
SQL: Introduction and its Basic Commands
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
 
MySQL basics
MySQL basicsMySQL basics
MySQL basics
 
SQL(NEW).pptx
SQL(NEW).pptxSQL(NEW).pptx
SQL(NEW).pptx
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Sql server
Sql serverSql server
Sql server
 

Recently uploaded

一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
bopyb
 
A presentation that explain the Power BI Licensing
A presentation that explain the Power BI LicensingA presentation that explain the Power BI Licensing
A presentation that explain the Power BI Licensing
AlessioFois2
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
SaffaIbrahim1
 
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
xclpvhuk
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
javier ramirez
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
sameer shah
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
Social Samosa
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Aggregage
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
jitskeb
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
Bill641377
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
roli9797
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
Walaa Eldin Moustafa
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
vikram sood
 
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
Timothy Spann
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdfUdemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Fernanda Palhano
 
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
wyddcwye1
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 

Recently uploaded (20)

一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
 
A presentation that explain the Power BI Licensing
A presentation that explain the Power BI LicensingA presentation that explain the Power BI Licensing
A presentation that explain the Power BI Licensing
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
 
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
 
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdfUdemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
 
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 

SQL LECTURE.pptx

  • 4. Objects in a database
  • 7. DCL Command(Not to be used by us)
  • 9. Datatype – Char(30) & Varchar Char is better than Varchar in terms of processing speed but varchar is more memory efficient than char
  • 10. Selection of data type Need to understand all the data types to create a table with proper datatype for proper optimization
  • 11. Summary • Rest of the data types were explained which are available on LMS. • Whenever you open the client for SQL you have to mention which database you have to use within the server. Eg- use mydb (database name) • Client s/w doesn’t store any data on it, its always stored on the server. • WARNING- if you execute same command twice, it gets executed multiple times and it might result in addition of unnecessary data. • Values should be added in same exact order as table column name
  • 12. ‘NULL’ Datatype. Null is not 0. Null signifies unknown value. Can be used only with ‘is not’ command.
  • 13. DDL commands • DDL command is Data Definition Language command, used to define a type of dataset for table creation and modification of a table only • ‘DR CAT’ • D - DROP • R - RENAME • C - CREATE • A - ALTER • T - TRUNCATE
  • 14. Use and format of ALTER & RENAME
  • 15. TRUNCATE command • Truncate command deletes the entire Data or the Table content. • It internally executes 2 commands • Drops table entirely • Create fresh table with similar column • Truncate command cannot be rolled back. • Truncate comment will delete all the objects created above the table.
  • 16. DML commands • DML command stands for Data Manipulation Language • Used to manipulate data within the table • It is used to modify the data within the table • DML commands • Insert – to insert data • Update – to update existing data • Delete – to delete the record in data.
  • 17. Alternate way to use INSERT command • When we don’t know the values of multiple data and want to put NULL data type we can use the format to specify the data input.
  • 18. ‘Where’ clause in DML & DQL command
  • 20. ‘WHERE’ clause • Where clause is used to define a condition in a query or specific record • Type1- update students set sname = 'Thomas' where std_id = 1; • Type2- update students set course = ‘analytics’, marks = 25 where sname = ‘Thomas’ • Type3- update students set course = ‘ analytics’ (all change) • For NULL- update students set marks = 0 where course is null ‘HAVING’ clause • Having clause is used to select specific groups
  • 21. ‘Delete’ command • Syntax is similar to ‘update’ command • Delete from students where std_id = 1; • Delete from students, (will delete all the table records)
  • 22. DQL command – Select (will be used 85%*) • Different ways to use select command • Select * from myemp ; – shows everything • Select count(*) from myemp ; – shows count of rows • Select * from myemp limit 5 ; – limits data to 5 rows; • Select first_name, last _name,salary from myemp limit 10 ;
  • 23. Function of ‘SELECT’ • Select does not make any change in the backend. • It just shows you the desired output • Can help you make derived column(temp column) • Select first_name, last _name,salary, salary*0.2 from myemp limit 10 ; • We can use other arethmatic operators with ‘where’ clause. • select * from myemp where salary >= 10000; • select first_name,last_name,job_id,salary from myemp where salary >= 15000; • IN,BETWEEN,LIKE operators also exist for convenience
  • 24. Result table for AND & OR & IN operator select * from myemp where dep_id in (20,40,60); #use IN operator for multiple condition of same column
  • 25. Pattern matching for LIKE operator select * from myemp where first_name like 'j%'; #name starts with J select * from myemp where first_name like '%a'; #name ends with A
  • 26. Sorting the table – ‘ORDER BY’ • Order by clause is used ro sort the table according to particular column • Select * from myemp order by dep_id; - by default Ascending • Select * from myemp order by dep_id desc; Distinct function • To find out unique values in a table • Select distinct dep_id from myemp;
  • 27. String functions & operators • CONCAT() • LEFT • RIGHT() • LOWER() • UPPER() https://dev.mysql.com/doc/refman/8.0/en/string-functions.html Link for all string functions that can be used
  • 28. Date & Time functions • ADDDATE() • ADDTIME() • CURDATE() • CURTIME() • NOW() https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html Link for all DATE functions that can be used
  • 29. Group functions • SUM() • AVG() • MIN() • MAX() • STD()
  • 30. JOINS in mySQL • INNER JOIN • LEFT JOIN • RIGHT JOIN • CROSS JOIN • SELF JOIN • THE RESULTANT TABLE THAT WILL BE CREATED IS THE VIRTUAL TABLE RESPECTIVE OF THE TYPE OF JOIN USED.
  • 31. JOINS
  • 34. CROSS Join • It is irrespective to the common record. • Will join each record of left table to the corroponding each record of the right table.
  • 35. Using “PREFIX” and Alias Name • Its efficient to use prefix to be desprictive • Eg- select meals.mealname, drinks.drinkname • Alias name can be used if we are going to use similar name name multiple times in a table • We can use alias name for large table names to reduce the size of the query. • Eg- select d.drinks, m.meals from drinks as d cross join meals as m;
  • 40. Relations between parent and child table
  • 41. Create parent and Child Table
  • 42. TCL - Transaction control language
  • 43. Transaction-Except/Rollback/Savepoint/commit • Transaction/except – turns off autocommit and executes data or terminates. • Rollback – works like undo. Will work only if autocommit is off. • Savepoint – creates savepoint for rollback in between transaction. • Commit- Commit the data typed. We cant rollback once commitment is done.
  • 48. Views Can be used on “select’ to create a virtual table to select particular paramaters in a table but editing the view will also edit the main table Hyperlink- All about Views
  • 49. SEQUENCE object • Mysql doesn’t have a feature of creating a sequence hence we have to create a sequence implicitly. • create table mytab (id integer primary key auto_increment,name varchar (30),age integer);
  • 50. INDEX • Performance of the query is improved. • Search and Retrieval of data becomes faster. • Indexes youtube video
  • 51. Stored Procedures • Variables- Parameters & Local Variables • Local variables – are the variabls that a re written and declared within the procedure. • Create a procedure in procedures tabs in schemas • Stored Procedures is used to make a function Parameters Local Variables
  • 52. LOOPS