SlideShare a Scribd company logo
  DML [Data Manipulation Language]
Insert command It is used to add one or more rows to a table. Values are separated by commas Data types varchar2, char, raw, long and date are enclosed in single quotes. The value must be entered in the same order as they are defined in the table. Data can be entered for a specific column also.
Insert – Syntax and Example Syntax: Insert into <table_name> values (a list of data values); Example: [Empno N(4),  EName v2(15 ), Sal N(7,2), Comm N(8),  Design v(10 ), Deptno N(2)] Insert into Emp values(101, ’Ravi’, 5000,1000, ’Clerk’, 10);
To insert values in interactive mode Example: Insert into Emp values (&Empno,  ‘&Ename’,  &Sal, &Comm, ‘&Design’, &Deptno); Oracle prompts the user to enter values for all columns in the table as shown below: Enter value for Empno: Enter value for Ename: Enter value for Sal: Enter value for Comm: Enter value for Design: Enter value for Deptno: To repeat type / at SQL> prompt
To insert values for specific columns Syntax: Insert into <table_name(Col_names)> values (list of values); Example: Insert into Emp ( Empno, Ename, Deptno )    values ( 102, ‘Anitha’, 20 );
To insert values for specific columns – using null Syntax: Insert into <table_name> values (list of values); Example: Insert into Emp values ( 102, ‘Anitha’,null,null,null,20 ); SQL will prompt a message  1 row inserted
Inserting date values Date values must be enclosed within  single quotes . Standard format for date data types is  “DD-MON-YY”. Assuming a column DOJ – Date of Joining in Emp table Example: Insert into Emp values(103,’Harathi’,15000,2000,’Engineer’, 40, ’04-May-02’ );
Inserting values from the other table Replace the values clause with appropriate query. Columns returned by the query must be of the same type. Target-table-name is Employee1. Source table-name is Employee. For all columns Syntax: Insert into <target-table-name>  select * from <source-table-name> <where condition> Example: Insert into Employee1  select * from Employee;
For few columns Syntax: Insert into <target table-name> (column-name1,column-name2,…) select (source table col1, col2, …) from Source table <where condtion>; Example: Insert into Employee1 (Empno, Ename, Doj)  select  Empno, Ename, Doj  from  Employee;
Select command To retrieve information from a table. This is called as  Querying . Syntax: Select column_name1,column-name2, . ..  From table_name ..  ; Example: Select * from Emp; The * in the query displays all the columns from the table. The output can be obtained for selected columns. The order of the column names in the query can be as required.
Querying for a particular columns Example: Select  Empno, Ename, Deptno  from  Emp ; It will display the only the selected columns for all the employees in the table.
Select command with ‘Where’ clause WHERE clause in the SELECT statement, user can still filter the records based on the requirements  It is used to obtain the output based on some condition[s]. Syntax: Select <columnname1>,< columnname3 >,< columnname3 >, from <table name>  where  <condition> ; Example: Select * from Emp where Empno=101; The where clause retrieves specific row or rows based on the condition from a table.
Updating Column(s) values of the Table UPDATE  command is used  to update the columns in a table. Values of a  single column  or a  group of columns  can be updated. Update statement can affect a  single row  or a  set of rows  depending on the WHERE clause in the update statement.
Updating a single column: Syntax:  UPDATE <TABLE-NAME>  SET <COLUMN-NAME> = <NEW-VALUE>  <WHERE CONDITION>; Example:  The following example updates the COMM column to 1000 in EMP table. UPDATE EMP  SET COMM = 1000; Without a WHERE clause in the above example, it will update all the records in the EMP table.   
Update  using WHERE clause The following example will update the COMM column to 1000 in the EMP table for the  Employee 7788 using  WHERE  clause. UPDATE EMP SET COMM = 1000  WHERE EMPNO = 7788; Updating multiple columns: Syntax: UPDATE <TABLE-NAME>  SET <COLUMN1> =  < VALUE1>, <COLUMN2> = <VALUE2> . . .  <WHERE CONDITION>; Example:  UPDATE EMP  SET SAL = 2500, COMM = 500, MGR = 7900  WHERE EMPNO = 7934; Updating a single row or multiple rows is Subject to the WHERE clause.  
Deleting Row(s) from a Table DELETE  command is used to delete a row(s) from the table. All the rows will be deleted with a single DELETE command if you do not give WHERE clause. DELETE command used to delete a single row or a set of rows from the table is subject to the WHERE clause. Syntax: DELETE <TABLE-NAME> ;   Example: DELETE EMP (OR) DELETE FROM EMP;   The  FROM  keyword between  DELETE  and  EMP  is optional only, which doesn’t make any difference in the DELETE action.  
Deleting a single record Syntax:   Delete <Table-name> <Where Condition>;   Note: WHERE clause in the above syntax should identify a single record in the table, otherwise there is a chance to delete more than one record.   The following example will delete an employee from EMP table whose EMPNO = 7788;   Example: Delete Emp Where Empno = 7788;  
Deleting group of records Syntax:   Delete <Table-name> <Where Condition>;   Example: Delete Emp Where Deptno = 10 ;  
On Delete Cascade     Row(s) cannot be deleted from a table when there is matching records in the child table.  It can be made possible with  ON DELETE CASCADE  option.  Whenever you delete a row(s) from parent table, then all the corresponding child rows will be deleted from the child table without any warning.  
Example: The following example is to create an EMPLOYEE table with ON DELETE CASCADE option. DEPT is a Parent Table for EMPLOYEE table.   CREATE TABLE EMPLOYEE (EMPNO NUMBER(4), ENAME VARCHAR2(20),  DEPTNO NUMBER(2) CONSTRAINT EMP_DNO_FK REFERENCES DEPT(DEPTNO)   ON DELETE CASCADE , SAL NUMBER(5));   Now whenever you delete a row from DEPT table, then all the corresponding rows will be deleted from EMPLOYEE table.     
The previous example illustrates the definition of  ON DELETE CASCADE  in column level creation. ON DELETE CASCADE can be created in the table level as well as using ALTER TABLE (DDL) command.   ON DELETE CASCADE option should come along with declaration of foreign key constraint only . It cannot be given separately after creating the foreign key constraint.  
Transaction Control Language (TCL) Commit Rollback and Savepoint The  COMMIT  command is used to make changes to data (inserts, updates, deletes) permanently. The  ROLLBACK  command is used to discard parts of work or all the work the user has done in the current transaction. The  Savepoint  statements are used discard or commit all the changes upto a point.
TCL contd.. The changes made by the user are not physically written to the table.   The user has only a view of his/her work. Other users have access to these tables to continue to work. The COMMIT command is used to make the changes permanent to the database.  The user can continue with any number of inserts, updates and/or deletion, and still can undo the work by issuing the ROLLBACK command.  This is important in a case when an error id detected during these operations.
SQL has the facility to automatically commit all the work, without explicitly issuing the COMMIT command: Example: SET AUTOCOMMIT ON :Enables autocommit feature. SET AUTOCOMMIT OFF :Is the default and disables  the automatic committing. Set Autocommit command can be issued with value. Example:   SET AUTOCOMIT 3; The above Example will determine the 3 DML commands after which Oracle will issue a commit automatically. SET AUTOCOMMIT ON, without any value, by default is takes 1 as a value.   Oracle will issue an automatic commit after each DML operation .
Implicit Commit   The actions that force a commit to occur, even without issuing the COMMIT command are:     Creating any objects like Table, Views, Synonym etc.,(DDL operation). Altering any objects through ALTER TABLE command (DDL operation). Dropping any objects like Tables, Views, Synonym etc.,(DDL operation). Granting and Revoking rights (DCL operations). Connecting or Disconnecting from ORACLE.   Quit or Exit from SQL.
Rollback Auto Rollback   After completion of any DML statement, if the user experiences serious difficulty such as hardware failure and no explicit commit  is made, ORACLE will automatically ROLLBACK all un-committed work.
1.  SELECT * FROM STUDENT;   SID  SNAME  COURSE   -----  -----------  ------------    120  RAJIV  ORACLE   121  PRIYANKA  JAVA   122  ALEX  D2K 2. INSERT INTO STUDENT VALUES(123, 'SALIM', 'VB6'); 3.  INSERT INTO STUDENT VALUES(124, 'LAXMAN', 'ASP'); 4. SELECT * FROM STUDENT;   SID  SNAME  COURSE ---  ----------  -------------   120  RAJIV  ORACLE 121  PRIYANKA  JAVA   122  ALEX  D2K   123  SALIM  VB6   124  LAXMAN  ASP 5.  ROLLBACK;
6. SELECT * FROM STUDENT;   SID  SNAME  COURSE ------  -----------  -------------- 120  RAJIV  ORACLE 121  PRIYANKA  JAVA 122  ALEX  D2K ROLLBACK command in the 5 th  statement discards the two-insert statement, which are issued in 2nd, and 3 rd  statement.
7.  UPDATE STUDENT SET COURSE = 'DEVELOPER 2000' WHERE SID = 122; 8.    SELECT * FROM STUDENT;   SID  SNAME  COURSE -----  -----------  -------------  120  RAJIV  ORACLE 121  PRIYANKA  JAVA 122  ALEX  DEVELOPER 2000 7)           9.    COMMIT;
10.  SELECT * FROM STUDENT; SID  SNAME  COURSE ----  --------    ---------- 120  RAJIV  ORACLE 121  PRIYANKA  JAVA 122  ALEX  DEVELOPER 2000 Update Student Set Sname = 'Rajiv Roy' Where Sid = 120; 12. SELECT * FROM STUDENT;   SID  SNAME  COURSE ----  ----------    ------------- 120  RAJIV ROY  ORACLE 121  PRIYANKA  JAVA 122  ALEX  DEVELOPER 2000 13.   ROLLBACK;  
14. Select * from Student’ SID  SNAME  COURSE -----  ------------  -------------- 120  RAJIV  ORACLE 121  PRIYANKA  JAVA 122  ALEX  DEVELOPER 2000 ROLLBACK command in the 13 th  statement has discarded the 11 th  statement.  ROLLBACK command will  undo  only the statements, which are found after the latest COMMIT command (it could be implicit, explicit or autocommit).
Savepoint Suppose the user has  inserted a few rows into the EMP table updated a row and deleted a row  Then he/she realize that they have deleted a wrong row.  Normally, the tendency is to discard the entire transaction even though the insertions and updations are valid.  Because if commit is applied, a valid row entry will be lost. This can be handled with the use of  SAVEPOINTS.
What is a SavePoint? Savepoint is a point within a single logical transaction identified by a name and it’s purpose is to group or partition statements in a single logical statement.  So that, one can  ROLLBACK TO A SPECIFIC POINT IN THE TRANSACTION.
Points to be noted while naming savepoints are: Savepoint names must be unique to a transaction. If the name of a new savepoint within a transaction is same as the earlier one then new one replaces the earlier one. Once a COMMIT or an un-conditional ROLLBACK is  issued, all the savepoints are erased. Implicit commit too erases all the Savepoints. Savepoint name must start with Alphabet. Savepoint name is not case sensitive .

More Related Content

PPTX
Sql commands
PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
PPTX
SQL(DDL & DML)
PDF
SQL Overview
PPTX
SQL - DML and DDL Commands
PDF
SQL Joins With Examples | Edureka
PPTX
introdution to SQL and SQL functions
PPTX
Aggregate functions in SQL.pptx
Sql commands
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
SQL(DDL & DML)
SQL Overview
SQL - DML and DDL Commands
SQL Joins With Examples | Edureka
introdution to SQL and SQL functions
Aggregate functions in SQL.pptx

What's hot (20)

PDF
PL/SQL TRIGGERS
PPT
SQL select statement and functions
PPT
Using the set operators
PPTX
Triggers
PPT
MYSQL - PHP Database Connectivity
PPTX
SQL Basics
PPTX
SQL Commands
PPTX
Packages in PL/SQL
PPTX
Sql and Sql commands
PPT
Constraints In Sql
PPT
MySQL and its basic commands
PDF
View & index in SQL
PPT
Introduction to structured query language (sql)
PDF
Sql tutorial
PPTX
Collections and its types in C# (with examples)
ODP
PPTX
Sql Constraints
PPTX
Lab2 ddl commands
PPTX
SQL Joins.pptx
PPT
Sequences and indexes
PL/SQL TRIGGERS
SQL select statement and functions
Using the set operators
Triggers
MYSQL - PHP Database Connectivity
SQL Basics
SQL Commands
Packages in PL/SQL
Sql and Sql commands
Constraints In Sql
MySQL and its basic commands
View & index in SQL
Introduction to structured query language (sql)
Sql tutorial
Collections and its types in C# (with examples)
Sql Constraints
Lab2 ddl commands
SQL Joins.pptx
Sequences and indexes
Ad

Viewers also liked (15)

PDF
Introduction to My SQL
PPTX
Ppt INFORMATIVE PRACTICES for class 11th chapter 14
PDF
Programming Design Guidelines
PPT
Graph theory concepts complex networks presents-rouhollah nabati
PDF
PDF
Dbms viva questions
DOCX
DBMS lab manual
DOC
Sql queires
DOC
Dbms lab questions
DOC
DBMS Practical File
DOC
Best sql plsql material
PDF
Top 100 SQL Interview Questions and Answers
PPT
Data Base Management System
DOC
A must Sql notes for beginners
DOC
Sql queries with answers
Introduction to My SQL
Ppt INFORMATIVE PRACTICES for class 11th chapter 14
Programming Design Guidelines
Graph theory concepts complex networks presents-rouhollah nabati
Dbms viva questions
DBMS lab manual
Sql queires
Dbms lab questions
DBMS Practical File
Best sql plsql material
Top 100 SQL Interview Questions and Answers
Data Base Management System
A must Sql notes for beginners
Sql queries with answers
Ad

Similar to Sql dml & tcl 2 (20)

PPTX
My SQL.pptx
PDF
Data Definition Language (DDL)
PPT
PPT
Sql query [select, sub] 4
PPT
Oracle naveen Sql
PPT
Oracle naveen Sql
ODP
Mysqlppt
ODP
Prabu's sql quries
ODP
Babitha2.mysql
ODP
Babitha2 Mysql
PPTX
8. sql
PPTX
Commands
PPTX
SQL Class Note By Amit Maity PowerPoint Presentation
DOC
PPT
Les08 (manipulating data)
PPTX
SQL Tutorial for Beginners
PPT
DOCX
ii bcom dbms SQL Commands.docx
My SQL.pptx
Data Definition Language (DDL)
Sql query [select, sub] 4
Oracle naveen Sql
Oracle naveen Sql
Mysqlppt
Prabu's sql quries
Babitha2.mysql
Babitha2 Mysql
8. sql
Commands
SQL Class Note By Amit Maity PowerPoint Presentation
Les08 (manipulating data)
SQL Tutorial for Beginners
ii bcom dbms SQL Commands.docx

More from Dr. C.V. Suresh Babu (20)

PPTX
Data analytics with R
PPTX
Association rules
PPTX
PPTX
Classification
PPTX
Blue property assumptions.
PPTX
Introduction to regression
PPTX
Expert systems
PPTX
Dempster shafer theory
PPTX
Bayes network
PPTX
Bayes' theorem
PPTX
Knowledge based agents
PPTX
Rule based system
PPTX
Formal Logic in AI
PPTX
Production based system
PPTX
Game playing in AI
PPTX
Diagnosis test of diabetics and hypertension by AI
PPTX
A study on “impact of artificial intelligence in covid19 diagnosis”
PDF
A study on “impact of artificial intelligence in covid19 diagnosis”
Data analytics with R
Association rules
Classification
Blue property assumptions.
Introduction to regression
Expert systems
Dempster shafer theory
Bayes network
Bayes' theorem
Knowledge based agents
Rule based system
Formal Logic in AI
Production based system
Game playing in AI
Diagnosis test of diabetics and hypertension by AI
A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”

Recently uploaded (20)

PPTX
Tartificialntelligence_presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Spectroscopy.pptx food analysis technology
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
Tartificialntelligence_presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Network Security Unit 5.pdf for BCA BBA.
Spectral efficient network and resource selection model in 5G networks
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
1. Introduction to Computer Programming.pptx
Machine Learning_overview_presentation.pptx
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
Spectroscopy.pptx food analysis technology
gpt5_lecture_notes_comprehensive_20250812015547.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding

Sql dml & tcl 2

  • 1. DML [Data Manipulation Language]
  • 2. Insert command It is used to add one or more rows to a table. Values are separated by commas Data types varchar2, char, raw, long and date are enclosed in single quotes. The value must be entered in the same order as they are defined in the table. Data can be entered for a specific column also.
  • 3. Insert – Syntax and Example Syntax: Insert into <table_name> values (a list of data values); Example: [Empno N(4), EName v2(15 ), Sal N(7,2), Comm N(8), Design v(10 ), Deptno N(2)] Insert into Emp values(101, ’Ravi’, 5000,1000, ’Clerk’, 10);
  • 4. To insert values in interactive mode Example: Insert into Emp values (&Empno, ‘&Ename’, &Sal, &Comm, ‘&Design’, &Deptno); Oracle prompts the user to enter values for all columns in the table as shown below: Enter value for Empno: Enter value for Ename: Enter value for Sal: Enter value for Comm: Enter value for Design: Enter value for Deptno: To repeat type / at SQL> prompt
  • 5. To insert values for specific columns Syntax: Insert into <table_name(Col_names)> values (list of values); Example: Insert into Emp ( Empno, Ename, Deptno ) values ( 102, ‘Anitha’, 20 );
  • 6. To insert values for specific columns – using null Syntax: Insert into <table_name> values (list of values); Example: Insert into Emp values ( 102, ‘Anitha’,null,null,null,20 ); SQL will prompt a message 1 row inserted
  • 7. Inserting date values Date values must be enclosed within single quotes . Standard format for date data types is “DD-MON-YY”. Assuming a column DOJ – Date of Joining in Emp table Example: Insert into Emp values(103,’Harathi’,15000,2000,’Engineer’, 40, ’04-May-02’ );
  • 8. Inserting values from the other table Replace the values clause with appropriate query. Columns returned by the query must be of the same type. Target-table-name is Employee1. Source table-name is Employee. For all columns Syntax: Insert into <target-table-name> select * from <source-table-name> <where condition> Example: Insert into Employee1 select * from Employee;
  • 9. For few columns Syntax: Insert into <target table-name> (column-name1,column-name2,…) select (source table col1, col2, …) from Source table <where condtion>; Example: Insert into Employee1 (Empno, Ename, Doj) select Empno, Ename, Doj from Employee;
  • 10. Select command To retrieve information from a table. This is called as Querying . Syntax: Select column_name1,column-name2, . .. From table_name .. ; Example: Select * from Emp; The * in the query displays all the columns from the table. The output can be obtained for selected columns. The order of the column names in the query can be as required.
  • 11. Querying for a particular columns Example: Select Empno, Ename, Deptno from Emp ; It will display the only the selected columns for all the employees in the table.
  • 12. Select command with ‘Where’ clause WHERE clause in the SELECT statement, user can still filter the records based on the requirements It is used to obtain the output based on some condition[s]. Syntax: Select <columnname1>,< columnname3 >,< columnname3 >, from <table name> where <condition> ; Example: Select * from Emp where Empno=101; The where clause retrieves specific row or rows based on the condition from a table.
  • 13. Updating Column(s) values of the Table UPDATE command is used to update the columns in a table. Values of a single column or a group of columns can be updated. Update statement can affect a single row or a set of rows depending on the WHERE clause in the update statement.
  • 14. Updating a single column: Syntax: UPDATE <TABLE-NAME> SET <COLUMN-NAME> = <NEW-VALUE> <WHERE CONDITION>; Example: The following example updates the COMM column to 1000 in EMP table. UPDATE EMP SET COMM = 1000; Without a WHERE clause in the above example, it will update all the records in the EMP table.  
  • 15. Update using WHERE clause The following example will update the COMM column to 1000 in the EMP table for the Employee 7788 using WHERE clause. UPDATE EMP SET COMM = 1000 WHERE EMPNO = 7788; Updating multiple columns: Syntax: UPDATE <TABLE-NAME> SET <COLUMN1> = < VALUE1>, <COLUMN2> = <VALUE2> . . . <WHERE CONDITION>; Example: UPDATE EMP SET SAL = 2500, COMM = 500, MGR = 7900 WHERE EMPNO = 7934; Updating a single row or multiple rows is Subject to the WHERE clause.  
  • 16. Deleting Row(s) from a Table DELETE command is used to delete a row(s) from the table. All the rows will be deleted with a single DELETE command if you do not give WHERE clause. DELETE command used to delete a single row or a set of rows from the table is subject to the WHERE clause. Syntax: DELETE <TABLE-NAME> ;   Example: DELETE EMP (OR) DELETE FROM EMP;   The FROM keyword between DELETE and EMP is optional only, which doesn’t make any difference in the DELETE action.  
  • 17. Deleting a single record Syntax:   Delete <Table-name> <Where Condition>;   Note: WHERE clause in the above syntax should identify a single record in the table, otherwise there is a chance to delete more than one record.   The following example will delete an employee from EMP table whose EMPNO = 7788;   Example: Delete Emp Where Empno = 7788;  
  • 18. Deleting group of records Syntax:   Delete <Table-name> <Where Condition>;   Example: Delete Emp Where Deptno = 10 ;  
  • 19. On Delete Cascade   Row(s) cannot be deleted from a table when there is matching records in the child table. It can be made possible with ON DELETE CASCADE option. Whenever you delete a row(s) from parent table, then all the corresponding child rows will be deleted from the child table without any warning.  
  • 20. Example: The following example is to create an EMPLOYEE table with ON DELETE CASCADE option. DEPT is a Parent Table for EMPLOYEE table.   CREATE TABLE EMPLOYEE (EMPNO NUMBER(4), ENAME VARCHAR2(20), DEPTNO NUMBER(2) CONSTRAINT EMP_DNO_FK REFERENCES DEPT(DEPTNO) ON DELETE CASCADE , SAL NUMBER(5));   Now whenever you delete a row from DEPT table, then all the corresponding rows will be deleted from EMPLOYEE table.     
  • 21. The previous example illustrates the definition of ON DELETE CASCADE in column level creation. ON DELETE CASCADE can be created in the table level as well as using ALTER TABLE (DDL) command.   ON DELETE CASCADE option should come along with declaration of foreign key constraint only . It cannot be given separately after creating the foreign key constraint.  
  • 22. Transaction Control Language (TCL) Commit Rollback and Savepoint The COMMIT command is used to make changes to data (inserts, updates, deletes) permanently. The ROLLBACK command is used to discard parts of work or all the work the user has done in the current transaction. The Savepoint statements are used discard or commit all the changes upto a point.
  • 23. TCL contd.. The changes made by the user are not physically written to the table.   The user has only a view of his/her work. Other users have access to these tables to continue to work. The COMMIT command is used to make the changes permanent to the database. The user can continue with any number of inserts, updates and/or deletion, and still can undo the work by issuing the ROLLBACK command. This is important in a case when an error id detected during these operations.
  • 24. SQL has the facility to automatically commit all the work, without explicitly issuing the COMMIT command: Example: SET AUTOCOMMIT ON :Enables autocommit feature. SET AUTOCOMMIT OFF :Is the default and disables the automatic committing. Set Autocommit command can be issued with value. Example: SET AUTOCOMIT 3; The above Example will determine the 3 DML commands after which Oracle will issue a commit automatically. SET AUTOCOMMIT ON, without any value, by default is takes 1 as a value. Oracle will issue an automatic commit after each DML operation .
  • 25. Implicit Commit   The actions that force a commit to occur, even without issuing the COMMIT command are:   Creating any objects like Table, Views, Synonym etc.,(DDL operation). Altering any objects through ALTER TABLE command (DDL operation). Dropping any objects like Tables, Views, Synonym etc.,(DDL operation). Granting and Revoking rights (DCL operations). Connecting or Disconnecting from ORACLE.   Quit or Exit from SQL.
  • 26. Rollback Auto Rollback   After completion of any DML statement, if the user experiences serious difficulty such as hardware failure and no explicit commit is made, ORACLE will automatically ROLLBACK all un-committed work.
  • 27. 1. SELECT * FROM STUDENT; SID SNAME COURSE ----- ----------- ------------ 120 RAJIV ORACLE 121 PRIYANKA JAVA 122 ALEX D2K 2. INSERT INTO STUDENT VALUES(123, 'SALIM', 'VB6'); 3. INSERT INTO STUDENT VALUES(124, 'LAXMAN', 'ASP'); 4. SELECT * FROM STUDENT;   SID SNAME COURSE --- ---------- ------------- 120 RAJIV ORACLE 121 PRIYANKA JAVA 122 ALEX D2K 123 SALIM VB6 124 LAXMAN ASP 5. ROLLBACK;
  • 28. 6. SELECT * FROM STUDENT;   SID SNAME COURSE ------ ----------- -------------- 120 RAJIV ORACLE 121 PRIYANKA JAVA 122 ALEX D2K ROLLBACK command in the 5 th statement discards the two-insert statement, which are issued in 2nd, and 3 rd statement.
  • 29. 7. UPDATE STUDENT SET COURSE = 'DEVELOPER 2000' WHERE SID = 122; 8.   SELECT * FROM STUDENT;   SID SNAME COURSE ----- ----------- ------------- 120 RAJIV ORACLE 121 PRIYANKA JAVA 122 ALEX DEVELOPER 2000 7)           9.   COMMIT;
  • 30. 10. SELECT * FROM STUDENT; SID SNAME COURSE ---- -------- ---------- 120 RAJIV ORACLE 121 PRIYANKA JAVA 122 ALEX DEVELOPER 2000 Update Student Set Sname = 'Rajiv Roy' Where Sid = 120; 12. SELECT * FROM STUDENT;   SID SNAME COURSE ---- ---------- ------------- 120 RAJIV ROY ORACLE 121 PRIYANKA JAVA 122 ALEX DEVELOPER 2000 13. ROLLBACK;  
  • 31. 14. Select * from Student’ SID SNAME COURSE ----- ------------ -------------- 120 RAJIV ORACLE 121 PRIYANKA JAVA 122 ALEX DEVELOPER 2000 ROLLBACK command in the 13 th statement has discarded the 11 th statement. ROLLBACK command will undo only the statements, which are found after the latest COMMIT command (it could be implicit, explicit or autocommit).
  • 32. Savepoint Suppose the user has inserted a few rows into the EMP table updated a row and deleted a row Then he/she realize that they have deleted a wrong row. Normally, the tendency is to discard the entire transaction even though the insertions and updations are valid. Because if commit is applied, a valid row entry will be lost. This can be handled with the use of SAVEPOINTS.
  • 33. What is a SavePoint? Savepoint is a point within a single logical transaction identified by a name and it’s purpose is to group or partition statements in a single logical statement. So that, one can ROLLBACK TO A SPECIFIC POINT IN THE TRANSACTION.
  • 34. Points to be noted while naming savepoints are: Savepoint names must be unique to a transaction. If the name of a new savepoint within a transaction is same as the earlier one then new one replaces the earlier one. Once a COMMIT or an un-conditional ROLLBACK is issued, all the savepoints are erased. Implicit commit too erases all the Savepoints. Savepoint name must start with Alphabet. Savepoint name is not case sensitive .