Ticker

6/recent/ticker-posts

Header Ads Widget

Responsive Advertisement

SQL DROP Or DELETE

 


SQL DROP / DELETE

The DROP command is used to remove an object/table from the database and database also by “DROP DATABASE” command. If you want to drop a table using “DROP TABLE” command, all the rows in the table are deleted and the table structure is removed from the database. Once a table is dropped we cannot get it back table and its records, so be careful while using DROP command because “DROP” Command removed the records of the table with deleting the structure of table also. When a table is dropped all the references to the table will not be valid.

Syntax:

DROP TABLE tableName;

 

Following is the example DROP CUSTOMERS table permanently from the database, Once CUSTOMERS table deleted from database, It can’t be recovered.

SQL > DROP TABLE CUSTOMERS;

 

Query Ok – Table Dropped

 

SQL DELETE

The SQL DELETE Query is used to delete the existing records from a table.

You can use WHERE clause with DELETE query to delete selected rows, otherwise all the records would be deleted.

 

Syntax:

DELETE FROM table_name

WHERE [condition];

You can combine N number of conditions using AND or OR operators.

 

Example:

Consider the CUSTOMERS table having the following records:

+----+-------------+------+-----------------+---------------+

| ID  | NAME      | AGE  | ADDRESS      | SALARY       |

+----+-------------+------+-----------------+---------------+

| 1    | Ramesh   | 32    | Ahmedabad   | 2000.00      |

| 2    | Khilan      | 25    | Delhi                | 1500.00      |

| 3    | kaushik   | 23    | Kota                 | 2000.00      |

| 4    | Chaitali    | 25   | Mumbai          | 6500.00       |

| 5    | Hardik     | 27    | Bhopal            | 8500.00       |

| 6    | Komal      | 22    | MP                   | 4500.00       |

| 7    | Muffy       | 24    | Indore            | 10000.00     |

+----+-------------+------+-----------------+---------------+

 

Following is an example, which would DELETE a customer, whose ID is 6:

 

SQL> DELETE FROM CUSTOMERS

WHERE ID = 6;

 

Now, CUSTOMERS table would have the following records:

Consider the CUSTOMERS table having the following records:

+----+-------------+------+-----------------+---------------+

| ID  | NAME      | AGE  | ADDRESS      | SALARY       |

+----+-------------+------+-----------------+---------------+

| 1    | Ramesh   | 32    | Ahmedabad   | 2000.00      |

| 2    | Khilan      | 25    | Delhi                | 1500.00      |

| 3    | kaushik   | 23    | Kota                 | 2000.00      |

| 4    | Chaitali    | 25   | Mumbai          | 6500.00       |

| 5    | Hardik     | 27    | Bhopal            | 8500.00       |

| 7    | Muffy       | 24    | Indore            | 10000.00     |

+----+-------------+------+-----------------+---------------+

 

If you want to DELETE all the records from CUSTOMERS table, you do not need to use WHERE clause and DELETE query would be as follows:

 

SQL> DELETE FROM CUSTOMERS;

Now, CUSTOMERS table would not have any record.

 

 




आशा करते है कि हमारे द्वारा लिखी हुई इस Post को आप Like, Share and Comment करेंगे | और हमें Comment करके बताये की आपको ये Post कैसी लगी | इसी तरह की Post और News पाने के लिए हमारे सभी Social Media Channels को रेगुलर Follow करे| 


Thanks
Amar Digital World
(Always Ready To Digital Serve)

Post a Comment

0 Comments