dec-1-MYSQL Commands
dec-1-MYSQL Commands
com/l/mysql_online_compiler
https://www.jdoodle.com/online-mysql-terminal
http://sqlfiddle.com/#!9/a6c585/1
DDL(Data Defination
DML(Data Manipulation
Language)
Language) DCL(Data Control Language)
e.g., create, alter, truncate,
e.g., select, insert, update, e.g., grant, revoke
drop, rename(change
delete
column-MySQL)
show databases;
use rextester;
show tables;
desc try1;
desc try1;
SELECT statement
Comparison operators
%, _
Logical operators
Joins, group by with aggregate functions, group by with HAVING clause, order by
- Find customer details whose name contains 3rd last character ‘X’.
alter table clientdata add constraint cons_fk foreign key (clientproject) references
projectdata(projectname);
alter table teams add constraint cons_fk1 foreign key (projectname) references
projectdata(projectname);
desc projectdata;
insert into projectdata values(1001, 'AutocallSOS',260);
desc teams;
desc clientdata;
Group by :
JOINS :
Set Theory :
Set A = {1,2,A}
Set B = {A, B, 1}
A×B = {(1,A),(1,B),(1,1),
(2,A),(2,B),(2,1),
(A,A),(A,B),(A,1)}
A B
Union : AUB = {1,2,A,B,A,1} = Full Outer join / non equality join (< or > or <> operators in query)
A B
Set B = {A, B, 1}
A-B = {2}
A B
B-A = {B}
A B
A B
A B
Teams
work
order
Projectdata
Clientdata
OUTER JOIN
/* MySQL does not support full outer join. It can be emulated using UNION of LEFT and RIGHT OUTER
JOINS */
union
String Functions :
ASCII
CHAR_LENGTH
CONCAT
FIND_IN_SET
FORMAT
INSERT
INSTR
LEFT
LENGTH
LOCATE
LOWER
LPAD
LTRIM
MID
POSITION
REPEAT
REPLACE
REVERSE
RIGHT
RPAD
RTRIM
STRCMP
SUBSTR
TRIM
UPPER
Date Functions :
CURDATE
CURTIME
ADDDATE
ADDTIME
DATEDIFF
DATE_FORMAT
DATE_SUB
DAYNAME
DAYOFMONTH
DAYOFWEEK
DAYOFYEAR
EXTRACT
HOUR
MINUTE
YEAR
QUARTER
MONTH
WEEK
DAY
MONTHNAME
TIME_FORMAT
Numeric Function :
ABS
AVG
CEIL
COUNT
DIV
EXP
FLOOR
GREATEST
LEAST
LOG
MAX
MIN
MOD
PI
POWER
RAND
ROUND
SQRT
SUM
TRUNCATE
select projectname,concat("Name of the project for ", projectid," is ",projectname) from projectdata;
Query1(query2);
select clientname from clientdata where clientproject = (select projectname from teams where
teamid=2003);
select clientname from clientdata where clientproject IN (select projectname from teams);
select clientname from clientdata where clientproject IN (select projectname from teams where
projectname IN (select projectname from projectdata where duration>700));
Objects of PL/SQL :
---Oracle Blocks----
DECLARE
BEGIN
dbms_output.put_line(Message);
END;
BEGIN
dbms_output.put_line(Message);
END;
declare
begin
dbms_output.put_line(proc13try());
end;
begin
end;
call proctry1();
begin
end;
call proctry12345678("Payease",@a);
select @a;
-->>>work upon using cursor with loop.
begin
LOOP
END LOOP;
end;