You are on page 1of 10

MySQL Training

By Sanjay Aggarwal
OpenSource Technologies Pvt.
Ltd.
http://www.opensourcetechnologie
s.com

Types of Joins
CROSS JOIN:-This type of join is the simplest join. The cross join result in
cartesian product of all the records from two tables.
select * from employee cross join department
INNER JOIN OR EQUI JOIN:-This is the type of join where tables are
combined based on a common column.
select * from employee , department where employee .deptid=
department.depid;
OUTER JOIN:- Join is used to combine all rows of one table with
matching rows from the other table and also show unmatchable records
from other table. It is used whenever multiple tables must be accessed
through a SQL SELECT statement
SELECT * FROM roseindia AS R
-> LEFT JOIN newstrack AS N
-> ON R.EmpId = N.EmpId
http://www.opensourcetechnologie
s.com

Triggers
A trigger is a named database object
that is associated with a table, and
that activates when a particular
event occurs for the table. Some
uses for triggers are to perform
checks of values to be inserted into a
table or to perform calculations on
values involved in an update.
http://www.opensourcetechnologie
s.com

Trigger Example
CREATE TRIGGER ins_sum BEFORE
INSERT ON account -> FOR EACH
ROW SET @sum = @sum +
NEW.amount;
create trigger bi_emps_fer before
insert on emps for each row begin
insert into audit (user_name,
table_name, update_date) values
(current_user(),emps,now()); end; //
http://www.opensourcetechnologie
s.com

Procedure Example
delimiter //
CREATE PROCEDURE simpleproc
(OUT param1 INT) -> BEGIN ->
SELECT COUNT(*) INTO param1
FROM t; ->
END//
delimiter ;
CALL simpleproc(@a);
http://www.opensourcetechnologie
s.com

Function Example
CREATE FUNCTION hello (s
CHAR(20)) RETURNS CHAR(50)
DETERMINISTIC -> RETURN
CONCAT('Hello, ',s,'!');
SELECT hello('world');

http://www.opensourcetechnologie
s.com

S.Pro Vs functions
There is one main difference between functions
and procedures.
A function must return a value and it can be only a
single value. Any number of parameters can be
passed in but only 1 value can be passed out. This
value coming out must be done via the RETURN.
A Procedure doesn't have to return anything. But it
can accept any number of parameters in and also
any number of parameters out. There is no
RETURN in a procedure.
http://www.opensourcetechnologie
s.com

Transaction
The START TRANSACTION or BEGIN
statement begins a new transaction.
COMMIT commits the current
transaction, making its changes
permanent. ROLLBACK rolls back the
current transaction, canceling its
changes. The SET autocommit
statement disables or enables the
default autocommit mode for the
current session.
http://www.opensourcetechnologie
s.com

Save points
SAVEPOINT identifier
ROLLBACK TO [SAVEPOINT] identifier
RELEASE SAVEPOINT identifier

http://www.opensourcetechnologie
s.com

Cursors
Cursor can be created inside the
stored procedures, functions and
triggers. Cursors are used for rows
iteration returned by a query on a
row-by-row basis. It is different from
typical SQL commands that operate
on all the rows in the set returned by
a query at one time.
http://www.opensourcetechnologie
s.com

You might also like