Introduction To SQL
Introduction To SQL
SQL
SQL- Structured Query Language
• SQL is standard a language for creating and manipulating databases.
It can retrieve data from a database through query processing.
It can insert records in a database.
It can update records in a database.
It can create new databases and tables and modify existing ones.
It allows modifying the security settings of the system.
• Advantages of SQL
Ease of use.
No coding required.
SQL is not a case sensitive language.
SQL can be linked to most of the other high level languages.
Classification of SQL Statements
SQL
COMMANDS
Create Insert
Alter Update Select
Truncate
Delete
Drop
Data Definition Language (DDL)
Commands
• Permits database tables to be created or deleted.
• Defines keys, specifies links between tables and impose constraints on
the table.
DDL COMMANDS
DDL
CREATE SHOW
ALTER DROP USE
DROP DATABASE
DROP TABLE
ADD
CREATE DATABASE
MODIFY
CREATE TABLE
DROP
CHANGE
Examples of DDL Commands
CREATE DATABASE : creates a new database.
USE command: to select and open an existing database.
SHOW command : to display all tables in an existing database.
CREATE TABLE : creates a new table in an existing database.
ALTER TABLE : modifies the structure of a table.
DROP TABLE /DATABASE: deletes a table/database.
Data Manipulation Language (DML)
commands
Helps user to manipulates data. Several DML commands available are :
1. INSERT INTO command : To insert new data(record) into a table.
2. UPDATE command : To insert or change the data ( tuple) in a table ( not
modifying the data type of a column).
3. DELETE command : To delete data(tuple) from a table( not deleting a
column).
Data Query Language(DQL)
commands
INT
Numeric
FLOAT
CHAR
MySQL Non-numeric or
Data Types String
VARCHAR
DATE
Date and Time
TIME
Numeric Data types
INT : It stores positive whole numbers upto 11 digits and negative whole numbers
upto 10 digits. The range of integer is from -2,147,483,648 to 1,147,483,647.
BIGINT :
FLOAT : Holds numbers with decimal point.
Non numeric (String) data types
CHAR(x) :
Fixed length string.
Stores ‘x’ number of characters in the string which has a fixed length.
A maximum 254 characters can be stored in a string.
The value of CHAR data type has to be enclosed in single quotes or double quotes.
VARCHAR(x):
Variable length string.
For example, address of a student can be declared as VARCHAR(25) to store the address up to
25 characters long.
VARCHAR will not leave unused spaces.
The value of CHAR data type has to be enclosed in single quotes or double quotes.
Date and Time
DATE :
Store date in ‘yyyy/mm/dd’ format or ‘yyyy-mm-dd’ format.
Stores year, month and date values.
Date values to be entered are to be enclosed in quotes.
TIME :
Store time in hh:mm:ss format.
Stores hour,minute and second values.
For example, time 12:30:45 where 12 means hours, 30 means minutes and 45
refers to seconds.