Professional Documents
Culture Documents
Chapter 7
What is SQL
SQL ( Structured Query Language) is standard programming language
SQL is used to communication with a data base According to ANSI
SQL statement are used to perform tasks such as update data on a
database or retrieve data from data base
Sql programming language was first
Developed on the 1970s by IBM
Historical background
The first version of sql initially called SEQUEL , was developed at IBM by
Chamberlin and Boyce early 1970s
Later formally standardized by American National standard institute
(ANSI)in 1986
The first non-commercial non-sql RDBMS was developed in 1974at the
U.C.Berkely
Types of database
PL/SQL
ORACLE
MYSQL
POSTGRESQL
MongoDB
MARINA DB
DB2
Memcached…..,
History of mysql
MySQL was created by a Swedish company MySQL AB, founded by David
Axmark, Allan Larsson and Michael "Monty" Widenius.
Sun Microsystems acquired MySQL AB in 2008
The first version of MYSQL appeared on 23 may 1995 Version 3.19
Still my sql 8.0 April 19, 2018
MYSQL architecture
Data types
Numeric data types
Int , float ,double , decimal
Date and time
Date , time ,timestamp ,date time
String
Char , varchar ,text ,
Large object data type (LOB)
BLOB,LONGTEXT,MEDIUMBLOB
spatial data types
Point, line string ,polygon ,geometry
My sql database
MySQL allows us to store and retrieve the data from the database in a
efficient way
We can create a database using the CREATE DATABASE statement
The database already exits it throws an error
SHOW DATABASES;
USE database_name;
DROP DATABASE database_name;
Mysql commands
DDL (data definition language)
Table is a collection of data, organized in terms of rows and
columns.
MySQL stores all the data in tables. Regardless of the prefix,
each MySQL database table consists of rows and columns.
DDL operations
Create
Alter table
truncate
Drop
Commant
Rename
DDL
Operation
cont.. command
Rollback (The database can be restored to the UPDATE STUDENT SET STUDENT_NAME =
last committed state) ‘Manish’ WHERE STUDENT_NAME = ‘Meena’;
ROLLBACK;
Save Point(The main use of the Save point INSERT into CLASS VALUES (101, ‘Rahul);
command is to save a transaction temporarily. Commit;
This way users can rollback to the point UPDATE CLASS SET NAME= ‘Tyler’ where id=
whenever it is needed.) 101
SAVEPOINT A;
Select * from Class;
Mysql clauses
Operation command
Where (used with SELECT, INSERT, UPDATE and DELETE SELECT *
clause to filter the results) FROM officers
WHERE address = 'Lucknow' ;
Distinct (used to remove duplicate records from the table and SELECT DISTINCT officer_name, address
fetch only the unique records.) FROM officers;
Right join
Inner join
The MySQL INNER JOIN is used to return all rows from multiple tables
where the join condition is satisfied.
SELECT columns
FROM table1
INNER JOIN table2
ON table1.column = table2.column;
Left join
The LEFT OUTER JOIN returns all rows from the left hand table specified
in the ON condition
only those rows from the other table where the join condition is fulfilled.
EX:
SELECT columns
FROM table1
LEFT [OUTER] JOIN table2
ON table1.column = table2.column;
Right Join
The Right Outer Join returns all rows from the RIGHT-hand table specified in the
ON condition
only those rows from the other table where he join condition is fulfilled.
EX:
SELECT columns
FROM table1
RIGHT [OUTER] JOIN table2
ON table1.column = table2.column;
Aggregate Functions
Functions Example
Count ( It is used when you need to count some SELECT COUNT
records of your table.) FROM officers;
Sum ( used to return the total summed value of an SELECT SUM (sal)
expression.) FROM employees
Avg ( the average value of an expression) SELECT AVG(sal) AS "Avg sal "
FROM employees
WHERE working_hours > 5;
Min(the minimum value from the table) SELECT MIN (sal)
FROM employees;
Max (the maximum value from the table) SELECT MAX (sal)
FROM employees;