SlideShare a Scribd company logo
OVRVIEW ON SQL COMMANDS
Dr.R.Shalini
Asistant Professor
Dept. BCA/IT
VISTAS
Definition of DBMS
A database is a collection of related data organized
in a way that data can be accessed, managed and updated.
Any piece of information can be a data, for example in
school database stu_id, name, std etc
DBMS is a system software for creating and
managing databases. It provides users and programmers
with a systematic way to create, retrieve, update and
manage data.
RDBMS
 RDBMS (Relational Database Management System)
 The data in RDBMS are stored in database objects
called tables.
 A table is a collection of related data entries and it
consists of columns and rows.
Structured Query Language(SQL)
SQL is the standard language for managing data in
Relational Database System.
All the Relational Database Management Systems
(RDMS) like MySQL, MS Access, Oracle, Sybase,
Informix, Postgres and SQL Server use SQL as their
standard database language.
Categories Of SQL
The four main categories of sql:
1. DML (Data Manipulation Language)
2. DDL (Data Definition Language)
3. DCL (Data Control Language)
4. TCL (Transaction Control Language)
Categories Of SQL Cont...
DDL command
DDL(Data Definition Language) which deals with database
schemas and descriptions, of how the data should reside in the
database.
 CREATE – create a new Table, database, schema.
 ALTER – alter existing table, column description.
 DROP – delete existing objects from database.
 RENAME – to rename a column or table.
Create Command
Create command used to create a table or a database.
Syntax:
create table table-name { column-name1 datatype1, column-
name2 datatype2, column-name3 datatype3, column-name4
datatype4 };
Example:
create table Student(id number(3), name varchar2(20), age
number(3));
Alter command
Alter command is used for alteration of table structures.
Syntax:
alter table table-name add(column-name datatype);
Example
alter table Student add(address char);
 alter table Student add(father-name varchar(60), mother name
varchar(60), dob date);
 alter table Student modify(address varchar(30));
Drop command
Drop query completely removes a table from database.
Syntax
 alter table table-name drop(column-name);
 drop table table-name;
Example
 alter table Student drop(address);
 drop table Student;
Rename command
Rename command is used to rename a table or column.
Syntax:
1.Rename table old-table-name to new-table-name;
2.Alter table tablename rename old-cloumn name to columnname;
Example :
1.Rename table Student to Student-record;
2.Alter table student rename address column to location;
DML command
DML( Data Manipulation Language) which deals with data
manipulation and includes SQL statements such SELECT, INSERT,
UPDATE, DELETE etc, and it is used to store, modify, retrieve, delete
and update data in a database.
 SELECT – select records from a table
 INSERT – insert new records
 UPDATE – update/Modify existing records
 DELETE – delete existing records
Insert command
Insert command is used to insert data into a table
Syntax
INSERT into table-name values(data1,data2,..);
Example
INSERT into Student values(102,'Alex',15);
Update command
Update command is used to update a row of a table.
Syntax
Update table-name set column-name = value where condition;
Example
 Update Student set age=18 where s_id=102;
 Update Student set s_name='Abhi',age=17 where s_id=103;
Delete command
Delete command is used to delete data from a table.
Syntax
DELETE from table-name;
Example
To Delete all Records from a Table
DELETE from Student;
To Delete a particular Record from a Table
DELETE from Student where s_id=103;
SELECT command
The SELECT statement is used to select data from a database.
The data returned is stored in a result table, called the result-set.
The SELECT statement has many optional clauses:
•WHERE specifies which rows to retrieve.
•GROUP BY groups rows sharing a property so that an aggregate function can be
applied to each group.
•HAVING selects among the groups defined by the GROUP BY clause.
•ORDER BY specifies an order in which to return the rows.
•DISTINCT keyword is used in conjunction with the SELECT statement to
eliminate all the duplicate records and fetching only unique records.
SELECT Command contd...
Syntax 1: Select * FROM table_name;
Syntax 2: Select column1, column2, columnN FROM table_name WHERE
[condition];
Ex1:SQL> Select Id, Name, Salary From Customers WHERE Salary >
2000;
Ex 2: SQL> Select Id, Name, Salary From Customers WHERE Name =
'Hardik';
Syntax 3: Select column1, column2, columnN FROM table_name WHERE
[condition1] AND [condition2]...AND [conditionN];
SELECT Command contd..
Ex1:Select Id, Name, Salary From Customers Where Salary > 2000 AND age <
25;
Ex2: Select Id, Name, Salary From Customers Where Salary > 2000 OR Age <
25;
Syntax 4:
SELECT column-list * from table-name order by asc|desc;
Ex 1:SELECT * from Emp order by salary;
Ex 2: SELECT * from Emp order by salary DESC;
SELECT Command contd..
Syntax5:
SELECT column_name, function (column_name) FROM
table_name WHERE condition GROUP BY
column_name;
Ex1 : SELECT name, age from Emp group by salary:
Ex2: Group by Statement with WHERE clause
SELECT name, salary from Emp where age > 25 group by salary;
SELECT command contd..
Like clause:It is used to find similar data from the table.
Two wildcard operators used in like clause.
 Percent sign % : represents zero, one or more than one character.
 Underscore sign _ : represents only one character.
Ex1: :SELECT * from Student where s_name like 'A%';
Ex2: SELECT * from Student where s_name like '_d%';
Ex3: SELECT * from Student where s_name like '%x';
DCL Command
Data Control Language(DCL) is used to control privilege in Database
The rights that allow the use of some or all of oracle's resources on the Server are
called PRIVILEGES
Privileges are of two types,
 System : creating session, table etc are all types of system privilege.
 Object : any command or query to work on tables comes under object privilege.
DCL defines two commands,
 Grant :Gives privileges to user for accessing database data
 Revoke :Take back for given privileges
DCL Command
Grant Syntax:
GRANT <object privileges> ON <object_name> TO <User_Name>[WITH GRANT
OPTION]
eg:1 GRANT ALL ON Student TO Mohd Imran WITH GRANT OPTION
eg:2 Grant Select, Update On Student To Fareen With Grant Option
To view the contents of the student table that belongs to Mohd Imran.
eg: Select * From Mohd Imran.Student;
DCL Command
Revoke Syntax:
Revoke <object_privileges> ON <Object_Name> FROM
<User_Name>
Eg: REVOKE UPDATE ON Student FROM Fareen
TCL Command
 Transaction Control Language(TCL) commands are used to
manage transactions in database.
 These are used to manage the changes made by DML statements
COMMIT :Permanent work save into database.
ROLLBACK :Restore database to original form since the last COMMIT.
SAVEPOINT :Create SAVEPOINT for later use ROLLBACK the new
changes
TCL Command
 Syntax: commit;
 Syntax: rollback to savepoint-name;
 Syntax: savepoint savepoint-name;
TCL Command
Example:
 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
TCL Command
The resultant table will look like,
Now rollback to savepoint B
rollback to B;
TCL Command
SELECT * from class;
The resultant table will look like
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.ppt

More Related Content

What's hot (20)

PPTX
DBMS Notes: DDL DML DCL
Sreedhar Chowdam
 
PPT
Introduction to structured query language (sql)
Sabana Maharjan
 
PPTX
Introduction to Database, Purpose of Data, Data models, Components of Database
kasthurimukila
 
PDF
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
PPTX
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
PPTX
Sql commands
Pooja Dixit
 
PPTX
Database Management - Lecture 2 - SQL select, insert, update and delete
Al-Mamun Sarkar
 
PPT
SQL Tutorial - Basic Commands
1keydata
 
PPTX
Introduction to database & sql
zahid6
 
PPT
Fundamentals of Database system
philipsinter
 
ODP
Sql commands
Balakumaran Arunachalam
 
PPT
Lecture 01 introduction to database
emailharmeet
 
PPTX
SQL(DDL & DML)
Sharad Dubey
 
PPTX
DATABASE CONSTRAINTS
sunanditaAnand
 
PPT
PL/SQL Introduction and Concepts
Bharat Kalia
 
PPTX
Aggregate function
Rayhan Chowdhury
 
PDF
View & index in SQL
Swapnali Pawar
 
PPTX
Sql Functions And Procedures
DataminingTools Inc
 
DBMS Notes: DDL DML DCL
Sreedhar Chowdam
 
Introduction to structured query language (sql)
Sabana Maharjan
 
Introduction to Database, Purpose of Data, Data models, Components of Database
kasthurimukila
 
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Sql commands
Pooja Dixit
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Al-Mamun Sarkar
 
SQL Tutorial - Basic Commands
1keydata
 
Introduction to database & sql
zahid6
 
Fundamentals of Database system
philipsinter
 
Lecture 01 introduction to database
emailharmeet
 
SQL(DDL & DML)
Sharad Dubey
 
DATABASE CONSTRAINTS
sunanditaAnand
 
PL/SQL Introduction and Concepts
Bharat Kalia
 
Aggregate function
Rayhan Chowdhury
 
View & index in SQL
Swapnali Pawar
 
Sql Functions And Procedures
DataminingTools Inc
 

Similar to Sql Commands_Dr.R.Shalini.ppt (20)

PPTX
Introduction to database and sql fir beginers
reshmi30
 
PDF
STRUCTURED QUERY LANGUAGE
SarithaDhanapal
 
PPTX
Lab
neelam_rawat
 
PPTX
DBMS UNIT-2.pptx ggggggggggggggggggggggg
Praveen Kumar
 
DOC
Oracle sql material
prathap kumar
 
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
PDF
SQL-Notes.pdf mba students database note
MrSushilMaurya
 
PPTX
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
PDF
SQL Notes
JitendraYadav351971
 
PPTX
SQL commands
GirdharRatne
 
PPTX
rdbms parul university oracle dbms bca mca
VaibhavSrivastav52
 
PDF
sql notes Provideby AGN HUB Tech & It Solutions
mohanagn2244
 
PDF
Chapter – 6 SQL Lab Tutorial.pdf
TamiratDejene1
 
PDF
1.Types of SQL Commands for mba students
MrSushilMaurya
 
DOC
Dbmsmanual
Sadhana Sreekanth
 
PPTX
An intoduction to sql and its components
Monika Jain DAIMSR
 
PDF
SQL_NOTES.pdf
AnshumanDwivedi14
 
PPTX
Introduction to sql new
SANTOSH RATH
 
PPTX
introdution to SQL and SQL functions
farwa waqar
 
PPTX
SQLSlide
OrtonRandyandy34534
 
Introduction to database and sql fir beginers
reshmi30
 
STRUCTURED QUERY LANGUAGE
SarithaDhanapal
 
DBMS UNIT-2.pptx ggggggggggggggggggggggg
Praveen Kumar
 
Oracle sql material
prathap kumar
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
SQL-Notes.pdf mba students database note
MrSushilMaurya
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
SQL commands
GirdharRatne
 
rdbms parul university oracle dbms bca mca
VaibhavSrivastav52
 
sql notes Provideby AGN HUB Tech & It Solutions
mohanagn2244
 
Chapter – 6 SQL Lab Tutorial.pdf
TamiratDejene1
 
1.Types of SQL Commands for mba students
MrSushilMaurya
 
Dbmsmanual
Sadhana Sreekanth
 
An intoduction to sql and its components
Monika Jain DAIMSR
 
SQL_NOTES.pdf
AnshumanDwivedi14
 
Introduction to sql new
SANTOSH RATH
 
introdution to SQL and SQL functions
farwa waqar
 
Ad

Recently uploaded (20)

PPTX
Difference between write and update in odoo 18
Celine George
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Difference between write and update in odoo 18
Celine George
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Horarios de distribución de agua en julio
pegazohn1978
 
Controller Request and Response in Odoo18
Celine George
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Ad

Sql Commands_Dr.R.Shalini.ppt

  • 1. OVRVIEW ON SQL COMMANDS Dr.R.Shalini Asistant Professor Dept. BCA/IT VISTAS
  • 2. Definition of DBMS A database is a collection of related data organized in a way that data can be accessed, managed and updated. Any piece of information can be a data, for example in school database stu_id, name, std etc DBMS is a system software for creating and managing databases. It provides users and programmers with a systematic way to create, retrieve, update and manage data.
  • 3. RDBMS  RDBMS (Relational Database Management System)  The data in RDBMS are stored in database objects called tables.  A table is a collection of related data entries and it consists of columns and rows.
  • 4. Structured Query Language(SQL) SQL is the standard language for managing data in Relational Database System. All the Relational Database Management Systems (RDMS) like MySQL, MS Access, Oracle, Sybase, Informix, Postgres and SQL Server use SQL as their standard database language.
  • 5. Categories Of SQL The four main categories of sql: 1. DML (Data Manipulation Language) 2. DDL (Data Definition Language) 3. DCL (Data Control Language) 4. TCL (Transaction Control Language)
  • 7. DDL command DDL(Data Definition Language) which deals with database schemas and descriptions, of how the data should reside in the database.  CREATE – create a new Table, database, schema.  ALTER – alter existing table, column description.  DROP – delete existing objects from database.  RENAME – to rename a column or table.
  • 8. Create Command Create command used to create a table or a database. Syntax: create table table-name { column-name1 datatype1, column- name2 datatype2, column-name3 datatype3, column-name4 datatype4 }; Example: create table Student(id number(3), name varchar2(20), age number(3));
  • 9. Alter command Alter command is used for alteration of table structures. Syntax: alter table table-name add(column-name datatype); Example alter table Student add(address char);  alter table Student add(father-name varchar(60), mother name varchar(60), dob date);  alter table Student modify(address varchar(30));
  • 10. Drop command Drop query completely removes a table from database. Syntax  alter table table-name drop(column-name);  drop table table-name; Example  alter table Student drop(address);  drop table Student;
  • 11. Rename command Rename command is used to rename a table or column. Syntax: 1.Rename table old-table-name to new-table-name; 2.Alter table tablename rename old-cloumn name to columnname; Example : 1.Rename table Student to Student-record; 2.Alter table student rename address column to location;
  • 12. DML command DML( Data Manipulation Language) which deals with data manipulation and includes SQL statements such SELECT, INSERT, UPDATE, DELETE etc, and it is used to store, modify, retrieve, delete and update data in a database.  SELECT – select records from a table  INSERT – insert new records  UPDATE – update/Modify existing records  DELETE – delete existing records
  • 13. Insert command Insert command is used to insert data into a table Syntax INSERT into table-name values(data1,data2,..); Example INSERT into Student values(102,'Alex',15);
  • 14. Update command Update command is used to update a row of a table. Syntax Update table-name set column-name = value where condition; Example  Update Student set age=18 where s_id=102;  Update Student set s_name='Abhi',age=17 where s_id=103;
  • 15. Delete command Delete command is used to delete data from a table. Syntax DELETE from table-name; Example To Delete all Records from a Table DELETE from Student; To Delete a particular Record from a Table DELETE from Student where s_id=103;
  • 16. SELECT command The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set. The SELECT statement has many optional clauses: •WHERE specifies which rows to retrieve. •GROUP BY groups rows sharing a property so that an aggregate function can be applied to each group. •HAVING selects among the groups defined by the GROUP BY clause. •ORDER BY specifies an order in which to return the rows. •DISTINCT keyword is used in conjunction with the SELECT statement to eliminate all the duplicate records and fetching only unique records.
  • 17. SELECT Command contd... Syntax 1: Select * FROM table_name; Syntax 2: Select column1, column2, columnN FROM table_name WHERE [condition]; Ex1:SQL> Select Id, Name, Salary From Customers WHERE Salary > 2000; Ex 2: SQL> Select Id, Name, Salary From Customers WHERE Name = 'Hardik'; Syntax 3: Select column1, column2, columnN FROM table_name WHERE [condition1] AND [condition2]...AND [conditionN];
  • 18. SELECT Command contd.. Ex1:Select Id, Name, Salary From Customers Where Salary > 2000 AND age < 25; Ex2: Select Id, Name, Salary From Customers Where Salary > 2000 OR Age < 25; Syntax 4: SELECT column-list * from table-name order by asc|desc; Ex 1:SELECT * from Emp order by salary; Ex 2: SELECT * from Emp order by salary DESC;
  • 19. SELECT Command contd.. Syntax5: SELECT column_name, function (column_name) FROM table_name WHERE condition GROUP BY column_name; Ex1 : SELECT name, age from Emp group by salary: Ex2: Group by Statement with WHERE clause SELECT name, salary from Emp where age > 25 group by salary;
  • 20. SELECT command contd.. Like clause:It is used to find similar data from the table. Two wildcard operators used in like clause.  Percent sign % : represents zero, one or more than one character.  Underscore sign _ : represents only one character. Ex1: :SELECT * from Student where s_name like 'A%'; Ex2: SELECT * from Student where s_name like '_d%'; Ex3: SELECT * from Student where s_name like '%x';
  • 21. DCL Command Data Control Language(DCL) is used to control privilege in Database The rights that allow the use of some or all of oracle's resources on the Server are called PRIVILEGES Privileges are of two types,  System : creating session, table etc are all types of system privilege.  Object : any command or query to work on tables comes under object privilege. DCL defines two commands,  Grant :Gives privileges to user for accessing database data  Revoke :Take back for given privileges
  • 22. DCL Command Grant Syntax: GRANT <object privileges> ON <object_name> TO <User_Name>[WITH GRANT OPTION] eg:1 GRANT ALL ON Student TO Mohd Imran WITH GRANT OPTION eg:2 Grant Select, Update On Student To Fareen With Grant Option To view the contents of the student table that belongs to Mohd Imran. eg: Select * From Mohd Imran.Student;
  • 23. DCL Command Revoke Syntax: Revoke <object_privileges> ON <Object_Name> FROM <User_Name> Eg: REVOKE UPDATE ON Student FROM Fareen
  • 24. TCL Command  Transaction Control Language(TCL) commands are used to manage transactions in database.  These are used to manage the changes made by DML statements COMMIT :Permanent work save into database. ROLLBACK :Restore database to original form since the last COMMIT. SAVEPOINT :Create SAVEPOINT for later use ROLLBACK the new changes
  • 25. TCL Command  Syntax: commit;  Syntax: rollback to savepoint-name;  Syntax: savepoint savepoint-name;
  • 26. TCL Command Example:  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
  • 27. TCL Command The resultant table will look like, Now rollback to savepoint B rollback to B;
  • 28. TCL Command SELECT * from class; The resultant table will look like