Structured Query
Language
Definition
A standardized query language
Request information from database
Used in relational database management system
Perform tasks such as create table, insert record, update data, retrieve data etc.
Used in Oracle, MySQL, etc
DDL(Data Definition Language)
Used to define the structure of database
Refers the set of SQL commands that can create and manipulate
the structure of database
DDL Commands: CREATE, ALTER, DROP
CREATE
Create a table
Syntax: CREATE TABLE table_name
(attribute1 data_type1,…........., attributen data_typen );
Example:
CREATE TABLE employees(
emp_id INT(5) PRIMARY KEY, name VARCHAR(50), address VARCHAR(100));
ALTER
1 2 3
Add, delete or Syntax: ALTER Example:
modify columns TABLE table_name ALTER TABLE
ADD COLUMN employees
column_name; ADD COLUMN email
VARCHAR(30);
DROP
Delete table
Syntax: DROP TABLE table_name;
Example: DROP TABLE student;
DML (Data Manipulation Language)
Are used for managing data in database
Includes commands to enable users to enter and manipulate
data in a database
DML commands: SELECT, INSERT, UPDATE, DELETE
INSERT
Insertion of new information to the database
Syntax: INSERT INTO table_name VALUES (v1, v2, …, vn);
Example: INSERT INTO employees(emp_id, name, address, email)
VALUES (1001, 'Hari', 'Kamladi', '
[email protected]');
SELECT
Retrieve information from database
Syntax: SELECT * FROM table_name;
Example: SELECT * FROM employees;
UPDATE
Modify or update values in database
Syntax: UPDATE table_name SET attribute='value' WHERE
condition;
Example: UPDATE emplyees SET email='[email protected]'
email='
[email protected] WHERE emp_id=1001;
DELETE
• Delete information from database
• Syntax: DELETE FROM table_name WHERE condition;
• Example: DELETE FROM emplyees WHERE emp_id=1004;
DCL(Data Control Language)
Is used to create
privileges to allow
DCL command:
user access to, and
GRANT, REVOKE
manipulation of
database.
GRANT
1 2 3
To grant privilege to Syntax: GRANT Example: GRANT
a user SELECT ON SELECT
table_name TO ON emplyees TO
user_name; ram_th;
REVOKE
To remove a privilege from a user
Syntax: REVOKE SELECT ON table_name
FROM user_name;
Example: REVOKE SELECT ON emplyees
FROM ram_th;