Structure
Query Language
DIT201 Database System
1
Struct Query Language
Database Server
DBMS
SQL
2
Types of Struct Query Language
3
Data Manipulation Language (DML)
Data Manipulation Language which deals with data
manipulation and includes most common SQL statements
● SELECT: Used to retrieve data from one or more database
tables based on specified conditions.
● INSERT: Used to add new records (rows) to a database table.
● UPDATE: Used to modify existing records in a database table.
● DELETE: Used to remove records from a database table.
4
Data Definition Language (DDL)
Data Definition Language, which deals with database schemas and
descriptions, of how the data should reside in the database.
● CREATE: to create new database objects, such as tables
● ALTER: alters the structure of the existing database object
● DROP: delete objects from the database
● TRUNCATE: remove all records from a table
5
Data Control Language (DCL)
Data Control Language which acts as an access specifier to
the database.
● GRANT: grant permissions to the user for running
DML(SELECT, INSERT, DELETE,…) commands on the table
● REVOKE: revoke permissions to the user for running
DML(SELECT, INSERT, DELETE,…) command on the
specified table
6
Transactional Control Language (TCL)
Transactional Control Language which acts as an manager for all
types of transactional data and all transactions.
● Roll Back: Used to cancel or Undo changes made in the
database
● Commit: It is used to apply or save changes in the database
● Save Point: It is used to save the data on the temporary basis
in the database
7
CREATE statement
CREATE: Used to create new database objects, such as tables,
views, indexes, and more. It defines the structure, data types,
and constraints for the object being created.
8
DROP mydb database if exists
9
CREATE DATABASE statement
CREATE DATABASE DatabaseName ;
10
CREATE TABLE statement
CREATE TABLE TableName (
DataName DataType PRIMARY KEY,
DataName DataType ,
DataName DataType ) ;
2
11
ALTER statement
ALTER: Used to modify the structure of existing database objects.
You can use ALTER to add, modify, or delete columns, change
data types, or make other structural changes.
12
ALTER TABLE statement
ALTER TABLE TableName
ADD COLUMN DataName DataType ;
13
ALTER TABLE statement
ALTER TABLE TableName
MODIFY COLUMN DataName DataType ;
ALTER TABLE TableName
DROP COLUMN DataName ;
ALTER TABLE TableName
RENAME COLUMN DataName TO NewDataName ;
14
DROP statement
DROP: Used to delete database objects such as tables, views,
and indexes. Once an object is dropped, it is permanently
removed from the database.
15
DROP TABLE statement
DROP TABLE TableName ;
16
DROP DATABASE statement
DROP DATABASE DatabaseName ;
17
DON’T
18
Setup Learning Environment
Database Server
DBMS
19
Import Database
2
20
SELECT statement
SELECT: Used to retrieve data from one or more database tables
based on specified conditions. The SELECT statement allows you
to specify which columns to retrieve, filter data using conditions
(WHERE clause), and sort the results.
21
SELECT statement
SELECT DataName, DataName, [DISTINCT DataName ], [ function(DataName) ]
FROM TableName
[WHERE DataName Condition Value [AND/OR DataName Condition DataValue] ] ;
[GROUP BY DataName ]
[ORDER BY DataName [ASC/DESC] ]
[LIMIT number]
SELECT * : Select all DataName
[] : Optional statement
22
SELECT statement
SELECT *
FROM TableName ;
23
SELECT statement
SELECT DataName SELECT DataName
FROM TableName ; DISTINCT DataName
FROM TableName ;
24
SELECT statement
SELECT DataName, DataName
FROM TableName
WHERE DataName Condition DataValue ;
25
SELECT statement
SELECT *
FROM TableName
ORDER BY DataName ;
26
INSERT statement
INSERT: Used to add new records (rows) to a database table. The
INSERT statement specifies the table and the values to be
inserted into each column.
27
INSERT statement
INSERT INTO TableName (DataName, DataName)
VALUES ( DataValue, DataValue) ;
28
INSERT statement
INSERT INTO TableName
VALUES (DataValue, DataValue) ;
Do not specify the name of the data. In case
you want to edit all of the data columns.
29
UPDATE statement
UPDATE: Used to modify existing records in a database table.
The UPDATE statement allows you to change the values of
specific columns based on specified conditions (WHERE clause).
30
UPDATE statement
UPDATE TableName
SET DataName = DataValue , DataName = DataValue
[WHERE DataName condition DataValue ] ;
31
UPDATE statement
UPDATE TableName
SET DataName = DataValue ;
If no conditions are specified, all columns in
each row will change.
32
DELETE statement
DELETE: Used to remove records from a database table. The
DELETE statement deletes rows that match certain conditions
specified in the WHERE clause.
33
DELETE statement
DELETE FROM TableName
[WHERE DataName condition DataValue ] ;
34
DELETE statement
DELETE FROM TableName ;
If no conditions are specified will result in all Data cannot be deleted. In case the data is
table data being deleted. referenced for use in another table.
35
End.
DIT201
36