ManeeshaK K
maneeshakk16@gmail.com
www.facebook.com/username
twitter.com/username
in.linkedin.com/in/Maneesha
7559813984
S...
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
docu...
SQL STATEMENTS
A query/command to perform a task in a
database.
CREATE
ALTER Data Definition Language(DDL)
DROP
INSERT
UPDATE Data Manipulation Language (DML)
DELETE
GRANT
REVOKE Data Co...
DDL - Data Definition Language
1. Create
To Create a Database.
Syntax :
create database databasename;
Eg :
create database...
To Create Table
Syntax :
create table <TableName>
(
ColumnName1 Datatype(Size) Constraint ,
ColumnName2 Datatype(Size) Con...
3. Alter Table
To change the structure of the table.
alter table tbl_student add (int_marks int(2));
alter table tbl_stude...
DML - Data Manipulation Language
1. Insert
To insert rows into a table.
Syntax :
insert into tablename(columnname1,columnn...
2. Select
To extract data from the database.
(SELECT identifies what columns FROM identifies which table)
Syntax :
select ...
3. Update
To change the contents(rows /columns) of the
table.
Syntax :
update tablename set columnname=values
where condit...
4. Delete
To delete rows from the table.
Syntax :
delete from tablename where [condition];
Eg :
delete from tbl_student wh...
DCL - Data Controll Language
1. Grant
Syntax :
grant privilage_type on tablename to
‘user_name'@'localhost';
Eg :
grant al...
2 . Revoke
Syntax :
revoke privilege_type on table_name from
‘user_name'@'localhost';
Eg :
revoke select on tbl_student fr...
FUNCTIONS
SQL - Functions
SQL functions are used for performing calculations
on data.
Types of Functions
Aggregate Functions
Scala...
Aggregate Functions
•The functions that can be applied to all rows in table or
to a subset of the table specified by the w...
pk_int_roll_no vchr_name int_marks
1 Anu 96
2 Veena 89
3 Amal 79
4 Reema 92
•select max(int_marks),min(int_marks),avg(int_...
•select count(pk_int_roll_no)as total_students from
tbl_student;
total_students
4
Group By
To group the result set by one or more column.
Often used in conjunction with aggregate function.
Syntax :
Select...
Scalar function
These functions return a single value for each values of a
particular column given as input.
•Lcase()
•Uca...
JOINS
JOINS
To combine rows from two or more tables.
Types of Joins ::
1. Inner join
2. Outer join
a) Left join
b) Right join
INNER JOIN
Returns all rows when there is at least one match in
BOTH tables.
Syntax :
select column_name(s) from table1 jo...
select stud_name,dept_name from tbl_student join tbl_dept
where dept_id=fk_int_dept_id;
stud_id stud_name fk_int_dept_id
1...
LEFT OUTER JOIN
Returns all rows from the left table (table1), with
the matching rows in the right table (table2).
Syntax ...
select stud_name,dept_name from tbl_student
left join tbl_dept where dept_id=fk_int_dept_id;
stud_id stud_name fk_int_dept...
RIGHT OUTER JOIN
Return all rows from the right table, and the matched
rows from the left table.
Syntax :
select column_na...
select stud_name,dept_name from tbl_student
lright join tbl_dept where dept_id=fk_int_dept_id;
stud_id stud_name fk_int_de...
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many con...
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ s...
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Sta...
Sql 
statements , functions  &  joins
Upcoming SlideShare
Loading in …5
×

Sql 
statements , functions & joins

610 views

Published on

Sql 
statements , functions & joins

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
610
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sql 
statements , functions & joins

  1. 1. ManeeshaK K maneeshakk16@gmail.com www.facebook.com/username twitter.com/username in.linkedin.com/in/Maneesha 7559813984 SQL STATEMENTS , FUNCTIONS & JOINS
  2. 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  3. 3. SQL STATEMENTS A query/command to perform a task in a database.
  4. 4. CREATE ALTER Data Definition Language(DDL) DROP INSERT UPDATE Data Manipulation Language (DML) DELETE GRANT REVOKE Data Control Language(DCL)
  5. 5. DDL - Data Definition Language 1. Create To Create a Database. Syntax : create database databasename; Eg : create database student; 2. Use Syntax : use databasename; Eg : use student;
  6. 6. To Create Table Syntax : create table <TableName> ( ColumnName1 Datatype(Size) Constraint , ColumnName2 Datatype(Size) Constraint , ------------------------------------------------------- ); Eg : create table tbl_student ( pk_int_roll_no int(4) not null primary key, vchr_name varchar(20), char_gender char(2) );
  7. 7. 3. Alter Table To change the structure of the table. alter table tbl_student add (int_marks int(2)); alter table tbl_student drop column char_gender; alter table tbl_student change vchr_name vchr_name varchar(30); 4. Drop Table To remove the tables. Syntax : drop table tablename; Eg : drop table tbl_student;
  8. 8. DML - Data Manipulation Language 1. Insert To insert rows into a table. Syntax : insert into tablename(columnname1,columnname2,…)values(value1,value2,…); Eg : insert into tbl_student(pk_int_roll_no,vchr_name,int_marks)values(1,’Anu’,96);
  9. 9. 2. Select To extract data from the database. (SELECT identifies what columns FROM identifies which table) Syntax : select * / [distinct]column_name from table_name where [condition]; Eg : •select * from tbl_student; •select pk_int_roll_no,vchr_name from tbl_student; •select vchr_name from tbl_student where int_marks>80;
  10. 10. 3. Update To change the contents(rows /columns) of the table. Syntax : update tablename set columnname=values where condition; Eg : update tbl_student set int_marks=89 where pk_int_roll_no=2;
  11. 11. 4. Delete To delete rows from the table. Syntax : delete from tablename where [condition]; Eg : delete from tbl_student where int_marks<40;
  12. 12. DCL - Data Controll Language 1. Grant Syntax : grant privilage_type on tablename to ‘user_name'@'localhost'; Eg : grant all on tbl_student to ‘manu’@’localhost’;
  13. 13. 2 . Revoke Syntax : revoke privilege_type on table_name from ‘user_name'@'localhost'; Eg : revoke select on tbl_student from ‘manu'@'localhost';
  14. 14. FUNCTIONS
  15. 15. SQL - Functions SQL functions are used for performing calculations on data. Types of Functions Aggregate Functions Scalar Functions
  16. 16. Aggregate Functions •The functions that can be applied to all rows in table or to a subset of the table specified by the where clause. •Functions return single value for a group of rows in the table. •Sum() •Avg() •Min() •Max() •Count()
  17. 17. pk_int_roll_no vchr_name int_marks 1 Anu 96 2 Veena 89 3 Amal 79 4 Reema 92 •select max(int_marks),min(int_marks),avg(int_marks) from tbl_student; Max(int_marks) min(int_marks) avg(int_marks) 96 79 81.7
  18. 18. •select count(pk_int_roll_no)as total_students from tbl_student; total_students 4
  19. 19. Group By To group the result set by one or more column. Often used in conjunction with aggregate function. Syntax : Select column_name, aggregate_function(column_name) from table_name group by column_name; Eg : Select vchr_name,sum(int_marks) from tbl_student group by vchr_name;
  20. 20. Scalar function These functions return a single value for each values of a particular column given as input. •Lcase() •Ucase() •Round() Eg : Select ucase(vchr_name) from tbl_student; Select lcase(vchr_name) from tbl_student; Select round(int_marks) from tbl_student where pk_int_roll_no=3;
  21. 21. JOINS
  22. 22. JOINS To combine rows from two or more tables. Types of Joins :: 1. Inner join 2. Outer join a) Left join b) Right join
  23. 23. INNER JOIN Returns all rows when there is at least one match in BOTH tables. Syntax : select column_name(s) from table1 join table2 on table1.column_name=table2.column_name;
  24. 24. select stud_name,dept_name from tbl_student join tbl_dept where dept_id=fk_int_dept_id; stud_id stud_name fk_int_dept_id 1 Anu 1 2 Veena 3 3 Abhi 2 4 John 1 dept_id dept_name 1 CS 2 EC 3 QS stud_name dept_name Anu CS Veena QS Abhi EC John CS I n n e r j o i n
  25. 25. LEFT OUTER JOIN Returns all rows from the left table (table1), with the matching rows in the right table (table2). Syntax : select column_name(s) from table1 left join table2 on table1.column_name=table2.column_name;
  26. 26. select stud_name,dept_name from tbl_student left join tbl_dept where dept_id=fk_int_dept_id; stud_id stud_name fk_int_dept_id 1 Anu 1 2 Veena 3 3 Abhi 4 4 John 1 dept_id dept_name 1 CS 2 EC 3 QS l e f t j o i n stud_name dept_name Anu CS Veena QS Abhi NULL John CS
  27. 27. RIGHT OUTER JOIN Return all rows from the right table, and the matched rows from the left table. Syntax : select column_name(s) from table1 right join table2 on table1.column_name=table2.column_name;
  28. 28. select stud_name,dept_name from tbl_student lright join tbl_dept where dept_id=fk_int_dept_id; stud_id stud_name fk_int_dept_id 1 Anu 1 2 Veena 3 3 Abhi 4 4 John 1 dept_id dept_name 1 CS 2 EC 3 QS R i g h t j o i n stud_name dept_name Anu CS Veena QS Abhi NULL John CS
  29. 29. Want to learn more about programming or Looking to become a good programmer? Are you wasting time on searching so many contents online? Do you want to learn things quickly? Tired of spending huge amount of money to become a Software professional? Do an online course @ baabtra.com We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
  30. 30. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
  31. 31. Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us

×