SlideShare a Scribd company logo
DATABASE SYSTEMS
STAFF NAME : D.SARITHA
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER APPLICATIONS
BON SECOURS COLLEGE FOR WOMEN
THANJAVUR
UNIT : III
CHAPTER : 3
TOPIC : SQL
STRUCTURED QUERY
LANGUAGE
• Structure Query Language(SQL) is a database
query language used for storing and
managing data in Relational DBMS.
• SQL was the first commercial language
introduced for E.F Codd's Relational model of
database.
• Today almost all RDBMS(MySql, Oracle,
Infomix, Sybase, MS Access) use SQL as the
standard database query language.
• SQL is used to perform all types of data
operations in RDBMS.
INTRODUCTION TO SQL
• This includes changes to the structure of the table like
creation of table, altering table, deleting a table etc.
• All DDL commands are auto-committed. That means it
saves all the changes permanently in the database.
DDL: DATA DEFINITION LANGUAGE
Command Description
create to create new table or
database
alter for alteration
truncate delete data from table
drop to drop a table
rename to rename a table
• DML commands are used for manipulating the data stored
in the table and not the table itself.
• DML commands are not auto-committed. It means changes
are not permanent to database, they can be rolled back.
DML: DATA MANIPULATION LANGUAGE
Command Description
insert to insert a new row
update to update existing row
delete to delete a row
merge merging two rows or two
tables
These commands are to keep a check on other commands
and their affect on the database.
It can also make any temporary change permanent.
TCL: TRANSACTION CONTROL LANGUAGE
Command Description
commit to permanently save
rollback to undo change
savepoint to save temporarily
Data control language are the commands to grant and take
back authority from any database user.
DCL: DATA CONTROL LANGUAGE
Command Description
grant grant permission of
right
revoke take back permission.
Data query language is used to fetch data from tables based
on conditions that we can easily apply.
DQL: DATA QUERY LANGUAGE
Command Description
select retrieve records from
one or more table
Data Definition Language
SQL: CREATE COMMAND
create is a DDL SQL command used to create a table
or a database in relational database management
system.
CREATE DATABASE <DB_NAME>;
Creating a Database
To create a database in RDBMS, create command is used.
Following is the syntax,
CREATE DATABASE Test;
Creating a Table
create command can also be used to create
tables
CREATE TABLE <TABLE_NAME> ( column_name1
datatype1, column_name2 datatype2,
column_name3 datatype3, column_name4
datatype4 );
CREATE TABLE Student( student_id INT,
name VARCHAR(100), age INT);
Most commonly used datatypes for Table columns
Datatype Use
INT used for columns which will store integer values.
FLOAT used for columns which will store float values.
DOUBLE used for columns which will store float values.
VARCHAR used for columns which will be used to store characters
and integers, basically a string.
CHAR used for columns which will store char values(single
character).
DATE used for columns which will store date values.
TEXT used for columns which will store text which is generally
long in length.
Here we have listed some of the most commonly used datatypes used
for columns in tables.
alter command is used for altering the table structure, such as,
•to add a column to existing table
•to rename any existing column
•to change datatype of any column or to modify its size.
•to drop a column from the table.
SQL: ALTER command
ALTER TABLE table_name ADD( column_name datatype);
ALTER TABLE student ADD( address VARCHAR(200) );
ALTER TABLE table_name modify( column_name datatype );
Add a column
Modify an existing Column
ALTER TABLE student MODIFY( address varchar(300));
Rename a Column
ALTER TABLE table_name RENAME old_column_name TO
new_column_name;
ALTER TABLE student RENAME address TO location;
Drop a Column
ALTER TABLE table_name DROP( column_name);
ALTER TABLE student DROP( address);
TRUNCATE command removes all the records from a table. But this command
will not destroy the table's structure.
TRUNCATE COMMAND
TRUNCATE TABLE table_name
TRUNCATE TABLE student;
DROP command completely removes a table from the database. This
command will also destroy the table structure and the data stored in it.
DROP COMMAND
DROP TABLE table_name
DROP TABLE student;
RENAME command is used to set a new name for any
existing table.
RENAME QUERY
RENAME TABLE old_table_name to
new_table_name
RENAME TABLE student to students_info;
Insert command is used to insert data into a table
DATA MANIPULATION LANGUAGE
INSERT COMMAND
INSERT INTO table_name VALUES(data1, data2, ...)
INSERT INTO student VALUES(101, 'Adam', 15);
UPDATE command is used to update any record of data in a table
UPDATE COMMAND
UPDATE table_name SET column_name = new_value WHERE
some_condition;
UPDATE student SET age=18 WHERE student_id=102;
DELETE command is used to delete data from a table.
DELETE COMMAND
DELETE FROM student WHERE s_id=103;
TRANSACTION CONTROL LANGUAGE(TCL) COMMANDS
Transaction Control Language(TCL) commands are used to manage
transactions in the database.
COMMIT command is used to permanently save any transaction into the
database.
COMMIT command
COMMIT;
This command restores the database to last commited state.
It is also used with SAVEPOINT command to jump to a savepoint in an
ongoing transaction.
ROLLBACK COMMAND
ROLLBACK TO savepoint_name;
SAVEPOINT command is used to temporarily save a transaction so that you can
rollback to that point whenever required.
SAVEPOINT COMMAND
SAVEPOINT savepoint_name;
INSERT INTO class VALUES(5, 'Rahul');
COMMIT;
UPDATE class SET name = 'Abhijit' WHERE id = '5';
SAVEPOINT A;
INSERT INTO class VALUES(6, 'Chris');
SAVEPOINT B;
INSERT INTO class VALUES(7, 'Bravo');
SAVEPOINT C;
SELECT * FROM class;
Using GRANT and REVOKE
Data Control Language(DCL) is used to control privileges in
Database.
Privileges are of two types,
System:
This includes permissions for creating session, table, etc and
all types of other system privileges.
Object:
This includes permissions for any command or query to
perform any operation on the database tables.
DCL Commands
GRANT: Used to provide any user access privileges or other
privileges for the database.
REVOKE: Used to take back permissions from any user.
Allow a User to create session
Not even allowed to login and create a session until and unless proper
permissions/privileges are granted to the user
GRANT CREATE SESSION TO username;
Granting Privileges
To allow a user to create tables in the database, we can use the below
command
GRANT CREATE TABLE TO username;
GRANT CREATE SESSION TO Bob;
GRANT CREATE TABLE TO Bob;
GRANT SELECT ON DEPARTMENT TO BOB;
GRANT UPDATE(BUDGET) ON DEPARTMENT TO BOB,ALLEN;
Grant permission to create any table
we can grant privileges to a user to create any table using the below
command,
GRANT CREATE ANY TABLE TO username
GRANT CREATE ANY TABLE TO ALLEN
Grant permission to drop any table
GRANT DROP ANY TABLE TO username
GRANT DROP ANY TABLE TO ALLEN
Roles
Authorization granted to individual users.
CREATE ROLE INSTRUCTOR;
GRANT SELECT ON TAKES TO INSTRUCTOR;
CREATE ROLE DEAN;
GRANT DEAN TO AMIT;
GRANT INSTRUCTOR TO DEAN
Authorization on views
To allow a user to create views in the database, we can use the below
command
CREATE VIEW Geo-instructor as (Select * from instructor
where dept-name = ‘Geology’;
Select * from Geo-Instructor;
GRANT REFERENCES(DEPT-NAME) ON DEPARTMENT TO MARINO;
GRANT SELECT ON DEPARTMENT TO BOB WITH GRANT OPTION;
Authorizations on schema
To allow a user to refer the keys in the tables, we can use the below
command
Transfer of Privileges
To allow a user to pass the information to other users in the database,
we can use the below command
To take back Permissions
REVOKE CREATE TABLE FROM username
REVOKE CREATE TABLE FROM ALLEN
REVOKE SELECT ON DEPARTMENT FROM AMIT, SATOSHI RESTRICT;
DQL: DATA QUERY LANGUAGE
SELECT statement to display data of the table, based on a condition.
s_id name age address
101 Adam 15 Chennai
102 Alex 18 Delhi
103 Abhi 17 Banglore
104 Ankit 22 Mumbai
Using WHERE Clause
Consider a table student,
SELECT s_id, name, age, address FROM student WHERE s_id = 101;
s_id name age address
101 Adam 15 chennai
SELECT s_id, name, age, address FROM student WHERE age between
15 and 18;
s_id name age address
103 Abhi 17 Banglore
Using Between operator
SELECT s_id, name, age, address FROM student WHERE age >= 15
and <= 20;
Using Comparision operator
s_id name age address
101 Adam 15 Chennai
102 Alex 18 Delhi
103 Abhi 17 Banglore
Using String Operations
LIKE clause compares data with an expression using wildcard operators to
match pattern given in the condition.
Wildcard operators
There are two wildcard operators that are used in LIKE clause.
• Percent sign %: represents zero, one or more than one character.
• Underscore sign _: represents only a single character.
SELECT * FROM Student WHERE name LIKE 'A%';
s_id name age address
101 Adam 15 Chennai
102 Alex 18 Delhi
103 Abhi 17 Banglore
104 Ankit 22 Mumbai
SELECT * FROM Student WHERE name LIKE '_d%';
s_id name age address
101 Adam 15 chennai
SELECT * FROM Student WHERE name LIKE '%x';
s_id name age address
102 Alex 18 Delhi
Using Escape Character ()
SELECT * FROM Student WHERE name LIKE ‘an%it';
s_id name age address
104 Ankit 22 Mumbai
Order by clause is used with SELECT statement for arranging retrieved data in
sorted order.
ORDER BY Clause
SELECT column-list|* FROM table-name ORDER BY ASC | DESC;
Syntax of Order By
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
Consider the following Emp table,
SELECT * FROM Emp ORDER BY salary;
eid name age salary
403 Rohan 34 6000
402 Shane 29 8000
405 Tiger 35 8000
401 Anu 22 9000
404 Scott 44 10000
SELECT * FROM Emp ORDER BY age desc;
eid name age salary
404 Scott 44 10000
405 Tiger 35 8000
403 Rohan 34 6000
402 Shane 29 8000
401 Anu 22 9000
Group by clause is used to group the results of a SELECT query
based on one or more columns.
Group By Clause
SELECT column_name, function(column_name) FROM
table_name WHERE condition GROUP BY column_name
SELECT name, age FROM Emp GROUP BY salary
Syntax
Example
THANK YOU

More Related Content

What's hot (20)

PPTX
Biorefinery
AMRATAMISHRA3
 
PPTX
MICROBIAL FUEL CELL
PraveenHM3
 
PPTX
Hidden markov model
UshaYadav24
 
PPTX
Wind power
Ahmed Nabil
 
PPTX
Bioinformatic, and tools by kk sahu
KAUSHAL SAHU
 
PDF
Structural databases
Dr.M.Priyadharshana
 
PDF
Animal transformation
Christabelle Cécile
 
PPTX
Nanofabrication techniques
Mohshina Afrooz
 
DOCX
Directed evolution
Ifrah Ishaq
 
PPT
Cryo electron microscopy
Madiheh
 
PDF
ORO 551 Renewable Energy Sources
Dr. Pradeep Kumar A R
 
PPTX
Nanoscale, nanotechnology
KAUSHAL SAHU
 
DOCX
Biomass conversion technologies
Pakistan Ordnance Factories
 
PPTX
Sequence and Structural Databases of DNA and Protein, and its significance in...
BibiQuinah
 
DOCX
Preparatiion of competent cells & Transformation Practical
Sabahat Ali
 
PPTX
Surface-Functionalized Nanoparticles for Controlled Drug Delivery
A Biodiction : A Unit of Dr. Divya Sharma
 
PPTX
Horizontal gene transfer
moincamacaro
 
PPTX
ARTIFICIAL SKIN AND ARTIFICIAL CARTILAGE
Felix Obi
 
PPTX
Synthetic cells
Fizza Khan
 
PPTX
System biology and its tools
Gaurav Diwakar
 
Biorefinery
AMRATAMISHRA3
 
MICROBIAL FUEL CELL
PraveenHM3
 
Hidden markov model
UshaYadav24
 
Wind power
Ahmed Nabil
 
Bioinformatic, and tools by kk sahu
KAUSHAL SAHU
 
Structural databases
Dr.M.Priyadharshana
 
Animal transformation
Christabelle Cécile
 
Nanofabrication techniques
Mohshina Afrooz
 
Directed evolution
Ifrah Ishaq
 
Cryo electron microscopy
Madiheh
 
ORO 551 Renewable Energy Sources
Dr. Pradeep Kumar A R
 
Nanoscale, nanotechnology
KAUSHAL SAHU
 
Biomass conversion technologies
Pakistan Ordnance Factories
 
Sequence and Structural Databases of DNA and Protein, and its significance in...
BibiQuinah
 
Preparatiion of competent cells & Transformation Practical
Sabahat Ali
 
Surface-Functionalized Nanoparticles for Controlled Drug Delivery
A Biodiction : A Unit of Dr. Divya Sharma
 
Horizontal gene transfer
moincamacaro
 
ARTIFICIAL SKIN AND ARTIFICIAL CARTILAGE
Felix Obi
 
Synthetic cells
Fizza Khan
 
System biology and its tools
Gaurav Diwakar
 

Similar to STRUCTURED QUERY LANGUAGE (20)

PPT
Sql Commands_Dr.R.Shalini.ppt
DrRShaliniVISTAS
 
DOCX
COMPUTERS SQL
Rc Os
 
PPTX
Introduction to database and sql fir beginers
reshmi30
 
PPTX
Database models and DBMS languages
DivyaKS12
 
PPTX
Lab
neelam_rawat
 
ODP
My sql
Nadhi ya
 
ODP
My sql Syntax
Reka
 
PPT
Creating a database
Rahul Gupta
 
PPTX
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
PPTX
sql.pptx
slavskrillex
 
DOC
Oracle sql material
prathap kumar
 
PPTX
Relational Database Language.pptx
Sheethal Aji Mani
 
PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
PPTX
Database COMPLETE
Abrar ali
 
PPTX
Database Management System PART- II.pptx
errvmaurya563
 
PPT
Mysql
TSUBHASHRI
 
PPTX
sql12.pptxsql12.pptxsql12.pptxsql12.pptx
usha raj
 
PDF
SQL_NOTES.pdf
AnshumanDwivedi14
 
PPTX
lovely
love0323
 
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
Sql Commands_Dr.R.Shalini.ppt
DrRShaliniVISTAS
 
COMPUTERS SQL
Rc Os
 
Introduction to database and sql fir beginers
reshmi30
 
Database models and DBMS languages
DivyaKS12
 
My sql
Nadhi ya
 
My sql Syntax
Reka
 
Creating a database
Rahul Gupta
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
sql.pptx
slavskrillex
 
Oracle sql material
prathap kumar
 
Relational Database Language.pptx
Sheethal Aji Mani
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Database COMPLETE
Abrar ali
 
Database Management System PART- II.pptx
errvmaurya563
 
Mysql
TSUBHASHRI
 
sql12.pptxsql12.pptxsql12.pptxsql12.pptx
usha raj
 
SQL_NOTES.pdf
AnshumanDwivedi14
 
lovely
love0323
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
Ad

Recently uploaded (20)

PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
PPTX
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PDF
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Ad

STRUCTURED QUERY LANGUAGE

  • 1. DATABASE SYSTEMS STAFF NAME : D.SARITHA ASSISTANT PROFESSOR DEPARTMENT OF COMPUTER APPLICATIONS BON SECOURS COLLEGE FOR WOMEN THANJAVUR UNIT : III CHAPTER : 3 TOPIC : SQL
  • 3. • Structure Query Language(SQL) is a database query language used for storing and managing data in Relational DBMS. • SQL was the first commercial language introduced for E.F Codd's Relational model of database. • Today almost all RDBMS(MySql, Oracle, Infomix, Sybase, MS Access) use SQL as the standard database query language. • SQL is used to perform all types of data operations in RDBMS. INTRODUCTION TO SQL
  • 4. • This includes changes to the structure of the table like creation of table, altering table, deleting a table etc. • All DDL commands are auto-committed. That means it saves all the changes permanently in the database. DDL: DATA DEFINITION LANGUAGE Command Description create to create new table or database alter for alteration truncate delete data from table drop to drop a table rename to rename a table
  • 5. • DML commands are used for manipulating the data stored in the table and not the table itself. • DML commands are not auto-committed. It means changes are not permanent to database, they can be rolled back. DML: DATA MANIPULATION LANGUAGE Command Description insert to insert a new row update to update existing row delete to delete a row merge merging two rows or two tables
  • 6. These commands are to keep a check on other commands and their affect on the database. It can also make any temporary change permanent. TCL: TRANSACTION CONTROL LANGUAGE Command Description commit to permanently save rollback to undo change savepoint to save temporarily
  • 7. Data control language are the commands to grant and take back authority from any database user. DCL: DATA CONTROL LANGUAGE Command Description grant grant permission of right revoke take back permission.
  • 8. Data query language is used to fetch data from tables based on conditions that we can easily apply. DQL: DATA QUERY LANGUAGE Command Description select retrieve records from one or more table
  • 9. Data Definition Language SQL: CREATE COMMAND create is a DDL SQL command used to create a table or a database in relational database management system. CREATE DATABASE <DB_NAME>; Creating a Database To create a database in RDBMS, create command is used. Following is the syntax, CREATE DATABASE Test;
  • 10. Creating a Table create command can also be used to create tables CREATE TABLE <TABLE_NAME> ( column_name1 datatype1, column_name2 datatype2, column_name3 datatype3, column_name4 datatype4 ); CREATE TABLE Student( student_id INT, name VARCHAR(100), age INT);
  • 11. Most commonly used datatypes for Table columns Datatype Use INT used for columns which will store integer values. FLOAT used for columns which will store float values. DOUBLE used for columns which will store float values. VARCHAR used for columns which will be used to store characters and integers, basically a string. CHAR used for columns which will store char values(single character). DATE used for columns which will store date values. TEXT used for columns which will store text which is generally long in length. Here we have listed some of the most commonly used datatypes used for columns in tables.
  • 12. alter command is used for altering the table structure, such as, •to add a column to existing table •to rename any existing column •to change datatype of any column or to modify its size. •to drop a column from the table. SQL: ALTER command ALTER TABLE table_name ADD( column_name datatype); ALTER TABLE student ADD( address VARCHAR(200) ); ALTER TABLE table_name modify( column_name datatype ); Add a column Modify an existing Column ALTER TABLE student MODIFY( address varchar(300));
  • 13. Rename a Column ALTER TABLE table_name RENAME old_column_name TO new_column_name; ALTER TABLE student RENAME address TO location; Drop a Column ALTER TABLE table_name DROP( column_name); ALTER TABLE student DROP( address);
  • 14. TRUNCATE command removes all the records from a table. But this command will not destroy the table's structure. TRUNCATE COMMAND TRUNCATE TABLE table_name TRUNCATE TABLE student; DROP command completely removes a table from the database. This command will also destroy the table structure and the data stored in it. DROP COMMAND DROP TABLE table_name DROP TABLE student;
  • 15. RENAME command is used to set a new name for any existing table. RENAME QUERY RENAME TABLE old_table_name to new_table_name RENAME TABLE student to students_info;
  • 16. Insert command is used to insert data into a table DATA MANIPULATION LANGUAGE INSERT COMMAND INSERT INTO table_name VALUES(data1, data2, ...) INSERT INTO student VALUES(101, 'Adam', 15); UPDATE command is used to update any record of data in a table UPDATE COMMAND UPDATE table_name SET column_name = new_value WHERE some_condition; UPDATE student SET age=18 WHERE student_id=102;
  • 17. DELETE command is used to delete data from a table. DELETE COMMAND DELETE FROM student WHERE s_id=103; TRANSACTION CONTROL LANGUAGE(TCL) COMMANDS Transaction Control Language(TCL) commands are used to manage transactions in the database. COMMIT command is used to permanently save any transaction into the database. COMMIT command COMMIT;
  • 18. This command restores the database to last commited state. It is also used with SAVEPOINT command to jump to a savepoint in an ongoing transaction. ROLLBACK COMMAND ROLLBACK TO savepoint_name; SAVEPOINT command is used to temporarily save a transaction so that you can rollback to that point whenever required. SAVEPOINT COMMAND SAVEPOINT savepoint_name; INSERT INTO class VALUES(5, 'Rahul'); COMMIT; UPDATE class SET name = 'Abhijit' WHERE id = '5'; SAVEPOINT A; INSERT INTO class VALUES(6, 'Chris'); SAVEPOINT B; INSERT INTO class VALUES(7, 'Bravo'); SAVEPOINT C; SELECT * FROM class;
  • 19. Using GRANT and REVOKE Data Control Language(DCL) is used to control privileges in Database. Privileges are of two types, System: This includes permissions for creating session, table, etc and all types of other system privileges. Object: This includes permissions for any command or query to perform any operation on the database tables. DCL Commands GRANT: Used to provide any user access privileges or other privileges for the database. REVOKE: Used to take back permissions from any user.
  • 20. Allow a User to create session Not even allowed to login and create a session until and unless proper permissions/privileges are granted to the user GRANT CREATE SESSION TO username; Granting Privileges To allow a user to create tables in the database, we can use the below command GRANT CREATE TABLE TO username; GRANT CREATE SESSION TO Bob; GRANT CREATE TABLE TO Bob; GRANT SELECT ON DEPARTMENT TO BOB; GRANT UPDATE(BUDGET) ON DEPARTMENT TO BOB,ALLEN;
  • 21. Grant permission to create any table we can grant privileges to a user to create any table using the below command, GRANT CREATE ANY TABLE TO username GRANT CREATE ANY TABLE TO ALLEN Grant permission to drop any table GRANT DROP ANY TABLE TO username GRANT DROP ANY TABLE TO ALLEN
  • 22. Roles Authorization granted to individual users. CREATE ROLE INSTRUCTOR; GRANT SELECT ON TAKES TO INSTRUCTOR; CREATE ROLE DEAN; GRANT DEAN TO AMIT; GRANT INSTRUCTOR TO DEAN Authorization on views To allow a user to create views in the database, we can use the below command CREATE VIEW Geo-instructor as (Select * from instructor where dept-name = ‘Geology’; Select * from Geo-Instructor;
  • 23. GRANT REFERENCES(DEPT-NAME) ON DEPARTMENT TO MARINO; GRANT SELECT ON DEPARTMENT TO BOB WITH GRANT OPTION; Authorizations on schema To allow a user to refer the keys in the tables, we can use the below command Transfer of Privileges To allow a user to pass the information to other users in the database, we can use the below command To take back Permissions REVOKE CREATE TABLE FROM username REVOKE CREATE TABLE FROM ALLEN REVOKE SELECT ON DEPARTMENT FROM AMIT, SATOSHI RESTRICT;
  • 24. DQL: DATA QUERY LANGUAGE SELECT statement to display data of the table, based on a condition. s_id name age address 101 Adam 15 Chennai 102 Alex 18 Delhi 103 Abhi 17 Banglore 104 Ankit 22 Mumbai Using WHERE Clause Consider a table student, SELECT s_id, name, age, address FROM student WHERE s_id = 101; s_id name age address 101 Adam 15 chennai
  • 25. SELECT s_id, name, age, address FROM student WHERE age between 15 and 18; s_id name age address 103 Abhi 17 Banglore Using Between operator SELECT s_id, name, age, address FROM student WHERE age >= 15 and <= 20; Using Comparision operator s_id name age address 101 Adam 15 Chennai 102 Alex 18 Delhi 103 Abhi 17 Banglore
  • 26. Using String Operations LIKE clause compares data with an expression using wildcard operators to match pattern given in the condition. Wildcard operators There are two wildcard operators that are used in LIKE clause. • Percent sign %: represents zero, one or more than one character. • Underscore sign _: represents only a single character. SELECT * FROM Student WHERE name LIKE 'A%'; s_id name age address 101 Adam 15 Chennai 102 Alex 18 Delhi 103 Abhi 17 Banglore 104 Ankit 22 Mumbai
  • 27. SELECT * FROM Student WHERE name LIKE '_d%'; s_id name age address 101 Adam 15 chennai SELECT * FROM Student WHERE name LIKE '%x'; s_id name age address 102 Alex 18 Delhi Using Escape Character () SELECT * FROM Student WHERE name LIKE ‘an%it'; s_id name age address 104 Ankit 22 Mumbai
  • 28. Order by clause is used with SELECT statement for arranging retrieved data in sorted order. ORDER BY Clause SELECT column-list|* FROM table-name ORDER BY ASC | DESC; Syntax of Order By eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 Consider the following Emp table,
  • 29. SELECT * FROM Emp ORDER BY salary; eid name age salary 403 Rohan 34 6000 402 Shane 29 8000 405 Tiger 35 8000 401 Anu 22 9000 404 Scott 44 10000 SELECT * FROM Emp ORDER BY age desc; eid name age salary 404 Scott 44 10000 405 Tiger 35 8000 403 Rohan 34 6000 402 Shane 29 8000 401 Anu 22 9000
  • 30. Group by clause is used to group the results of a SELECT query based on one or more columns. Group By Clause SELECT column_name, function(column_name) FROM table_name WHERE condition GROUP BY column_name SELECT name, age FROM Emp GROUP BY salary Syntax Example