Deleting Data

  The delete statement delete the single row as well as multiple rows from the table.

Syntax:

Deleting all rows:

     DELETE FROM Table_name;

     Here delete is the keyword and from specify the table in which we are going to delete the data  and table_name specify the name of the table.in this delete statement we can add a where clause  to delete rows according to some condition we can specify the where clause in the end of the statement.

Deleting selected rows:

    DELETE FROM Table_name WHERE  condition;


Example:



Delete all the employee whose department_id is 50

delete  from employee2
where dept_id=50


Delete all the employee

delete  from employee2


  The first statement delete only two rows i,e emp_id 198,199 rows will be deleted after processing this statement by oracle server where as the second statement delete all the rows from the employee2 table .So be carefull when you are writting any delete statement .For safety create a savepoint then perform the any delete operation so that u can rollback your data .we will learn about savepoint and rollback in coming lession .


I am interested in hearing your feedback, so that I can improve my articles and learning resources for you.connect with us on facebooktwitter

Share

Did you enjoy reading this and found it useful? If so, please share it with your friends:

Table creation with subquery

In this section we will disscuss about another methord of creating  a table. Let see how to create a table with the use of subquery but before this  we will see the meaning of subquery

Subquery:

“SQL statement embedded inside a another SQL statement is called a subquery “

Syntax:

CREATE TABLE Table_name (column1,column2,…..,column N) 
AS subquery

    In this syntax create table specify that creation of new table,Table_name specify the name of the table,column1, ….,column N etc specify the columns name of the table, AS is a keyword which states that we are going to create a new table from a exiting table,In subquery we can write the SQL select statement to select the rows from the other table.

Example:
 create a table employees2 from the exiting employees


CREATE TABLE EMPLOYEES2 (ID,FIRST_NAME,LAST_NAME,SALARY,DEPT_ID)
AS
SELECT EMPLOYEE_ID,FIRST_NAME,LAST_NAME,SALARY,DEPARTMENT_ID
FROM EMPLOYEES

Note : The above statement create a employees2 with the same structure and along with data of employees table.

I am interested in hearing your feedback, so that I can improve my articles and learning resources for you.connect with us on facebooktwitter

Share

Did you enjoy reading this and found it useful? If so, please share it with your friends: