Professional Documents
Culture Documents
HAMDANsql
HAMDANsql
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
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”
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 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 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
Output:
OR
Output:
AND
Output:
IN
Output:
IN
Output:
NOT
IN
Output:
>
Output:
<
Output:
>=
Output:
<=
Output:
<>
Output:
COUNT
Output:
COUNT WITH
DISTINCT
Output:
ORDER BY ASC
Output:
ORDER BY DESC
Output:
GROUP BY
Output:
LIMIT
Output:
Like (_%)
Output:
NOT LIKE (_
%)
Output:
BETWEEN
Output:
MYSQL CALCULATE
FUNCTION
❑ Sum
❑Average
❑Min
❑Max
❑Count
SUM
Output:
AVERAGE
Output:
MIN , MAX & COUNT
Output:
MYSQL STRING FUNCTION
❑Lcase
❑Ucase
❑Left
❑Right
❑Concat
❑Trim
❑Char_length
❑Mid
❑Length
L CASE
Output:
U CASE
Output:
LEFT & RIGHT
Output:
MYSQL DATE FUNCTION
❑ Date ADD
❑ Datediff
❑ Timestamp DIFF
❑ Date format
❑ Year
❑ Day
❑ Month
❑ Now
DATE ADD
Output:
DATEDIFF
Output:
DATE FORMAT
Output:
YEAR & DAY
Output:
MONTH & NOW
Output:
MYSQL LOGICAL FUNCTION
❑ If
❑ If with and condition
❑ If with or condition
IF
Output:
IF WITH AND CONDITION
Output:
IF WITH OR CONDITION
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
Output:
LEFT JOIN & RIGHT JOIN
Output:
CROSS JOIN
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
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