Ads Here

Friday 12 January 2018

Truncate and Drop Table in oracle database

Truncate Table:
We have learned how to create a table & alter a table. Now, let's see what is the use of Truncate Statement in a table. Truncate Statement is used for delete data from a table. Now, truncate deals with the data stored in a table & it directly not effect the table. But, still we categorized Truncate in DDL Statement because when we execute the truncate statement it free the memory of database by removing data from table. So, indirectly it is working as a DDL statement. Remember, that the truncate statement does not change the structure of the table.
As we discussed, Truncate Statement delete all data from the table. So, for work with the truncate statement we must have some data in our table. Now, inserting data into a table is the part of DML statement, that we discuss later in depth. So, for now you just understand how the truncate statement work. The basic syntax for Truncate is like this -
Syntax:


So, as you can see first we use the TRUNCATE keyword, after that we put the TABLE keyword and finally we put the name of the table which data we want to delete. So, when we execute this SQL statement this will delete all the data from the table which you want but is does not effect the structure of the table.
Drop Table:
Now, if you want to drop or delete a total table then we can also do that using DROP Statement. When you drop a table using DROP statement the table is totally deleted with the data stored in the table. Remember that you can not recover the table after delete and then you have to created anew one. The drop statement is like this -
Syntax:

So, first we use the DROP keyword, then the TABLE keyword & after that the table name you want to drop & at last a semicolon for complete the statement. Now, for explain you i have created a example table TEST1 with two columns. Now, for delete the
hello
So, aa, you can see i have created a example table and now we implement the DROP Statement.
So, as you can see we have executed the DROP Statement and after that it shows Table droped means the table is deleted. Now, when we use the DESC keyword it shows the object not found.
So, in this way you drop a table.
So, in this article you have learned how to truncate and drop a table. If anyone have any questions then ask me in the comments section below, thank you. 

No comments:

Post a Comment