Lesson3a-intro to mysql(prelim)
Lesson3a-intro to mysql(prelim)
What is SQL?
Stands for Standard Query Language.
Lets you access and manipulate
databases.
Is an ANSI (American National Standards
Institute) standard.
Is an open source software.
◦ Open source means “free software”
shared freely to the public.
Facts about MySQL
First release:
◦ May 23, 1995
Originally developed by:
◦ Michael Widenius and David Axmark
Developed by:
◦ MySQLAB
Facts about MySQL
2008:
◦ Sun Microsystems acquired MySQLAB
including the copyrights for MySQL
2009:
◦ Oracle corporation acquired the copyrights
for MySQL code base
Developed in:
◦ C/C++
License:
◦ GNU/General Public License
SQL capabilities
Queries against the database can be done
using SQL
Retrieval of records in a database
Insertion of records in a database
Updating of records in a database
Deletion of records in a database
Creation of new databases
Creation of new tables in a database
Creation of stored procedures in a database
Creation of views in a database
Permissions set on tables, procedures, and
views
Data Manipulation Language
(DML)
Is a set of syntax for querying ,
inserting, and updating of data in a
database. DML is the most popular
approach of retrieving information which
includes the following:
SYNTAX:
Example:
CREATE TABLE Employee1 (EmployeeNumber INT, Name
VARCHAR(15),Salary SMALLMONEY, Address VARCHAR(20));
Inserting values to the table
SYNTAX:
Example:
INSERT INTO Employee1 VALUES
(‘1’,’razel’,’10000’,’guihing’);
Extracts data from the
database
SELECT statement
Includes:
◦ SELECT clause – specifies the
columns to be displayed
◦ FROM clause – specifies the table
containing the columns that are to
be listed in the SELECT clause.
SELECT all columns
SYNTAX:
Example:
SELECT User_id, LastName, FirstName, Address,
City FROM Persons;
SELECT specific columns
SYNTAX:
Example:
SELECT User_id, LastName, FirstName FROM
Persons;
SYNTAX:
Example:
SELECT DISTINCT city FROM Persons;
How to use arithmetic operators
Operators: + , - , * , /
Example:
SELECT LastName, FirstName,Salary, Salary + 300 FROM
Employees;
◦ Operator precedence:
Multiplication and division occur before addition and
subtraction
Operators of the same priority are evaluated from left to right
Parenthesis are used to override the default precedence or to
clarify the statement
Example:
SELECT LastName, Salary, 12*Salary + 300 FROM
Employees;
How to use arithmetic operators
Using parenthesis
Example:
Column Alias:
Renames a column heading
Is useful with calculations
Immediately follows the column name
SYNTAX:
Example:
SELECT User_id, Salary AS
Annual_Compensation FROM Employees;
Sorting and restricting Data
how to limit rows:
If you want to display records that fulfill a specified condition,
WHERE clause can be used.
Column name
Comparison condition
Colum name, constant, or list values
SYNTAX:
Example:
SELECT E_id, Lastname FROM Employees WHERE E_id = 2;
Sorting and restricting Data
Example:
SELECT E_id, Lastname FROM Employees WHERE E_id
= 2;
SYNTAX:
Example:
SELECT E_id, Lastname FROM Employees WHERE
salary >= 3000;
Sorting and restricting Data
Example:
SELECT E_id, Lastname FROM Employees
WHERE salary BETWEEN 2000 AND 3000;
Example:
Example:
LOGICAL condition:
AND – returns true if both component
conditions are true
Example:
Example:
Example:
Example:
Example:
Example: