Hamdan SQL
Hamdan SQL
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”
●
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
❑Count
❑Or
❑Distinct
❑And
❑Count with distinct
❑In
❑Order by asc
❑Not in
❑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
❑Case with and statement
❑Left join
❑Case with or statement
❑Right join
❑RDBMS with subqueries
❑Cross join
❑Having clause
❑Full outer join
❑Basic joins trigger
❑Case and end
❑When
❑Then
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 \\
select emp_id,emp_name,
delimiter // OUTPUT :
begin
select dep_no;
end//;
delimiter ;
Output:
DECLARING VARIABLES
delimiter // OUTPUT :
begin
end//;
delimiter ;
Output:
MYSQL TRIGGERS
❑Trigger creation
❑Trigger timing
❑ Trigger with if statement
❑ Trigger with else if statement
BEFORE INSERT
Begin
end//;
delimiter ;
Output:
AFTER INSERT
delimiter
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 //
begin
end if;
end //
delimiter ;
= 18002;
THANK YOU