Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 68

MY SQL PROJECT

BY

HAMDAN MUSHARAF
WHAT IS MYSQL ??


MY SQL is the most popular open source relational
database management system.


MY SQL used for developing various wed based software
development.


Developed by company MySQL AB. (Based on CN C++).
MySQL Workbench


MySQL Workbench is a unified visual database designing or graphical user
interface tool used for working with database architects, developers, and
Database Administrators. It is developed and maintained by Oracle. It
provides


SQL development, data modeling, data migration, and comprehensive
administration tools for server configuration, user administration, backup,
and many more. We can use this Server Administration for creating new
physical data models, E-R diagrams, and for SQL development (run
queries, etc.). It is available for all major


operating systems like Mac OS, Windows, and Linux. MySQL Workbench


fully supports MySQL Server version v5.6 and higher.
MYSQL SERVERS
DIFFERENCE BETWEEN DBMS AND RDBMS

DBMS RDBMS

 Data stored is in the file format Data stored is in table format

 Individual access of data elements Multiple data elements are accessible


together
 No connection between data Data in the form of a table are linked
together
 There is normalization Normalization is not achievable

 No support for distributed database Support distributed database


Support distributed database
 Data stored is a small quantity Data is stored in a large amount
MYSQL STRING FUNCTION

SQL MYSQL
SQL is language to MYSQL is databases
manage databases software
SQL is used to query MYSQL stores the
database data
SQL does not provide It provides an
integrated tool called
“MYSQL Workbench”

SQL codes are used in MYSQL uses SQL for


oracle, SQL server, data management
PostgreSQL,DB2,MYS
QL.
DBMS KEYS


Primary key


Candidate key


Super key


Alternate key


Foreign key
PRIMARY KEY

A primary key is a special attribute or combination of attribute within a table that
uniquely identifies each row or record in that table.

CANDIDATE KEY
• Its is a super key no repeated data is called a candidate key.

SUPER KEY

A single key or a group of multiple keys that can uniquely identify tuples
in table.
ALTERNATE KEY


All the key which are not primary keys are called alternate
keys.

FOREIGN KEY

Its is a key it acts as a primary key in one table and if acts as
secondary key in a another table.
MYSQL FEATURES
CONTENT


MAIN COMMANDS


GENERAL FUNCTION


CALCULATE FUNCTION


STRING FUNCTION


DATE FUNCTION


LOGICAL FUNCTION


RDBMS SYSTEM


OIN QURIES
MY SQL MAIN COMMANDS
TABLE CREATION

create table emp_det(emp_id int,emp_name varchar(20),designation_id int,dep_no int, date_of_join


date,primary key(emp_id)); Select*from emp_det;
TABLE 2

Create table salary_info(salary_id int, Emp_id int, salary_date date, branch_id int, amount int, primary key
(salary_id));
Select*from salary_info;
TABLE 3 & TABLE 4:

Create table design_det(designation_id int, designation varchar(50),primary key(designation_id));


Select* from designation_det;

Create table dep_det(dep_no int, dep_name varchar(50), branch_id int, branch_name varchar(40) ; Select*from department_info
MYSQL GENERAL FUNCTION

❑Where
❑Or ❑Count
❑And ❑Distinct
❑In ❑Count with distinct
❑Not in ❑Order by asc
❑> ❑Order by desc
❑< ❑Group by
❑<= ❑Limit
❑>= ❑Like(_%)
❑<> ❑Not like
❑! ❑between
WHERE

QUERY : select*from emp_det where dep_no = 50;

Output:
OR

QUERY : select*from emp_det where dep_no = 50 or dep_no = 70;

Output:
AND

QUERY : select*from emp_det where dep_no = 50 and designation_id = 3006;

Output:
IN

QUERY : select*from emp_det where dep_no in (70,80,50);

Output:
IN

QUERY : select*from emp_det where dep_no in (70,80,50);

Output:
NOT
IN

QUERY : select*from emp_det where dep_no not in (70,80,50);

Output:
>

QUERY : select*from emp_det where dep_no > 50;

Output:
<

QUERY : select*from emp_det where dep_no < 80;

Output:
>=

QUERY : select*from emp_det where dep_no>=80;

Output:
<=

QUERY : select*from emp_det where dep_no<=80;

Output:
<>

QUERY : select*from emp_det where dep_no <> 50;

Output:
COUNT

QUERY : select count(emp_name)as count_workers from emp_det;

Output:
COUNT WITH
DISTINCT

QUERY : select count(distinct dep_no)as dep_no_count from emp_det;

Output:
ORDER BY ASC

QUERY : select*from emp_det order by emp_name asc;

Output:
ORDER BY DESC

QUERY : select*from emp_det order by emp_name desc;

Output:
GROUP BY

QUERY: select dep_no,count(emp_id)as emp_worker from emp_det group by dep_no;

Output:
LIMIT

QUERY: select *from emp_det limit 10,5;

Output:
Like (_%)

QUERY: select*from emp_det where emp_name like ‘v%';

Output:
NOT LIKE (_
%)

QUERY: select*from emp_det where emp_name not like 'v%';

Output:
BETWEEN

QUERY: select*from emp_det where dep_no between 70 and 80;

Output:
MYSQL CALCULATE
FUNCTION

❑ Sum
❑Average
❑Min
❑Max
❑Count
SUM

QUERY: select sum(dep_no) from emp_det;

Output:
AVERAGE

QUERY: select avg(dep_no) from emp_det;

Output:
MIN , MAX & COUNT

QUERY: select min(dep_no) from emp_det;


QUERY: select max(dep_no) from emp_det;
QUERY: select count(dep_no) from emp_det;

Output:
MYSQL STRING FUNCTION

❑Lcase

❑Ucase

❑Left

❑Right

❑Concat

❑Trim

❑Char_length

❑Mid

❑Length
L CASE

QUERY: select emp_name,lcase(emp_name) from emp_det;

Output:
U CASE

QUERY: select emp_name,ucase(emp_name) from emp_det;

Output:
LEFT & RIGHT

QUERY: select left(emp_id,2) from emp_det;


QUERY: select right(emp_id,2) from emp_det;

Output:
MYSQL DATE FUNCTION

❑ Date ADD
❑ Datediff
❑ Timestamp DIFF
❑ Date format
❑ Year
❑ Day
❑ Month
❑ Now
DATE ADD

QUERY: select*,date_add(date_of_join,interval 5 month)as joined_date from emp_det;

Output:
DATEDIFF

QUERY: select*,datediff(date_of_join,curdate())as joined_date from emp_det;

Output:
DATE FORMAT

QUERY: select*,date_format(date_of_join,'%b')as mounths from emp_det;

Output:
YEAR & DAY

QUERY: select*from emp_det where year(date_of_join)='2022';


QUERY: select*from emp_det where day(date_of_join)='11';

Output:
MONTH & NOW

QUERY: select*from emp_det where month(date_of_join)='05';


QUERY: select*,now()from emp_det;

Output:
MYSQL LOGICAL FUNCTION

❑ If
❑ If with and condition
❑ If with or condition
IF

QUERY: select*,if(dep_no>=50,'joins','fail')as workers_dep_no from emp_det;

Output:
IF WITH AND CONDITION

QUERY: select*,if(dep_no>=45,'join','not_join') as workers_dep_no,if((dep_no>=35) and (dep_no>=35) and


(dep_no>=65),'join','not_join') as ind_workers from emp_det;

Output:
IF WITH OR CONDITION

QUERY: select*,if(dep_no>=45,'join','not_join') as workers_dep_no,if((dep_no>=35)


or (dep_no>=35) or (dep_no>=65),'join','not_join') as ind_workers from emp_det;

Output:
MYSQL JOIN QUERIES

❑Inner join
❑Left join ❑Case with and statement
❑Right join
❑Cross join ❑Case with or statement
❑Full outer join
❑Case and end ❑RDBMS with subqueries
❑When
❑Then ❑Having clause
❑Double case with end statement
❑Basic joins trigger
INNER JOIN

QUERY: select*from emp_det inner join sal_det on emp_det.emp_id = sal_det.emp_id;

Output:
LEFT JOIN & RIGHT JOIN

QUERY: select*from emp_det left join sal_det on emp_det.emp_id = sal_det.emp_id;


QUERY: select*from emp_det right join sal_det on emp_det.emp_id = sal_det.emp_id;

Output:
CROSS JOIN

QUERY: select * from emp_det cross join dep_det;

Output:
CASE AND END

QUERY: select*,case when dep_no = '50' then 'procduction department'when dep_no = '60' then 'HR
department'when dep_no = '70' then 'sales department'when dep_no = '80' then 'finance
department'else 0end as workers_detfrom emp_det;

Output:
MYSQL PROCEDURES CONCEPTS

❑Procedure creation
❑Begin and end
❑Call procedures
❑Alter procedures
❑Declaring variables
❑Store variables
PROCEDURE CREATION
delimiter \\
create procedure workers_data_77()
select emp_id,emp_name,
Designation_id,
dep_no,date_of_j oin,
case when dep_no = '50' when dep_no = '80'
then 'procduction department' then 'finance department'
when dep_no = '60' else 0
then 'HR department' end as workers_det
when dep_no = '70' from emp_det where dep_no in
then 'sales department' (50,60,70,80);
end \\
delimiter ;
BEGIN AND END

delimiter // OUTPUT :
create procedure workers_data_()
begin
declare dep_no int;set dep_no = 80;
select dep_no;
end//;
delimiter ;

Output:
DECLARING VARIABLES

delimiter // OUTPUT :
create procedure workers_data_()
begin
declare dep_no int;set dep_no = 80;
select dep_no;
end//;
delimiter ;

Output:
MYSQL TRIGGERS

❑Trigger creation
❑Trigger timing
❑ Trigger with if statement
❑ Trigger with else if statement
BEFORE INSERT

QUERY: delimiter // OUTPUT :


create trigger dep_update before insert
on emp_id for each row
Begin
If new.dep_no <=40 then
Set new.dep_no =40;
end//;
delimiter ;

Output:
AFTER INSERT

delimiter
create trigger dep_no_backup after insert
on emp_id for each row
Begin
Insert into
emp_det_backup(emp_id,emp_name,
Designation_id,dep_no,date_of_join)
Values (new.emp_id,new.emp_name,new.
Designation_id,new.dep_no,new.date_of_j
oin)
end \\
delimiter ;
BEFORE UPDATE

delimiter //
create trigger sal_update before update on sal_det for each row
begin
if new.amount >=40000 then
set new.amount = 'High_salary';
elseif new.amount >=35000 then
set new.amount = 'good_salary';
elseif new.amount >=15000 then
set new.amount = 'Average_salary';
elseif new.amount >=0 then
set new.amount = 'Low_salary';
end if;
end //
delimiter ;
update sal_det set amount = 40000 where sal_id
= 18002;
THANK YOU

You might also like