SQL PHP HTML ASP JavaScript articles and free scripts to download
 

SQL DROP to remove table

We 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 field or some other properties associated with the table. Let us start with deleting a field by DROP command.

ALTER TABLE `content` DROP `dt`;

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 Table

We can use DROP command to remove a table inside the database. Now here is the code to delete the table content.

DROP TABLE content

Checking before deleting

We 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.

DROP TABLE IF EXISTS `content`;

Deleting multiple tables

We can use drop command to delete more than one table. Here is the command to remove 4 tables.

DROP TABLE `content`, `content_admin`, `content_cat`, `content_cmt_post`;

The above command will delete four tables.

Dropping a unique constraints

We can use DROP sql command to remove unique constraints associated to any column, here is an example.

ALTER TABLE 'content_cat' DROP INDEX 'cat_id'

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

DROP DATABASE TEST




Further readings
Changing structur of the table bu alter query
Create table query with if exists sql with php script
Creating a new table by using data from one table
Change the name of a table
Copying data from one table to another table
Delete records from a table with conditinos
Delete table by using DROP sql
Updating another table with data from main table
Update SQL commands
Inserting SUM, AVG data from one table column to other using group by command
Table Records are downloaded as .csv file
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Modify Table
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2013 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer