SQL DROP to remove tableWe have seen how to remove records from a table by using truncate sql command. Now we will learn how to use DROP query command to delete a table or a column or some other properties associated with the table. Let us start with deleting a Column of a table by DROP command.
Here content is our table name and dt is one of the field of this table. By this command we can delete the field dt of the table content.
Deleting a TableWe can use DROP command to remove a table inside the database. Now here is the code to delete the table content.
Checking before deletingWe can check whether table is there or not before giving any delete command. Without ensuring the presence of table ( non existence table ) delete command will generate an error message.
Deleting multiple tablesWe can use drop command to delete more than one table. Here is the command to remove 4 tables.
The above command will delete four tables.
Dropping a unique constraintsWe can use DROP sql command to remove unique constraints associated to any column, here is an example.
The above command will remove the unique index associated with cat_id field of content_cat table
We can also use DROP command to delete a complete database. Here is the sample code
PHP Code to Drop table