![]() But, the question is how we can do this using SQL commands? Well let's find out. ![]() Now suppose that we want to expand the existing shippers table by adding one more column. ALTER TABLE tablename DROP COLUMN columnname END OR IF (SELECT COUNT() FROM informationschema. We'll use this shippers table for all of our ALTER TABLE statements. | shipper_name | varchar(60) | NO | | NULL | | | shipper_id | int | NO | PRI | NULL | auto_increment | mysql> Select the database where the associated column which is going to be drop exist. Second, specify the name of the column that you want to drop in the DROP COLUMN clause. Type '\c' to clear the current input statement. | Field | Type | Null | Key | Default | Extra | First, specify the name of the table that contains the column which you want to drop after the ALTER TABLE keywords. ![]() This command delete the whole data from table. In such situation you can use the ALTER TABLE statement to alter or change an existing table by adding, changing, or deleting a column in the table.Ĭonsider we've a shippers table in our database, whose structure is as follows: Drop keyword is used to permantly delete table from Database. DROP TABLE IF EXISTS Test CREATE TABLE Test ( col1 INT, col2 INT, col3 INT ) SELECT FROM Test ALTER TABLE Test DROP COLUMN IF EXISTS col2, COLUMN IF EXISTS col3, COLUMN IF EXISTS col4 SELECT FROM Test In conclusion, I love the DROP IF EXISTS syntax even more now that I know how it works with columns and I also love being part of such an amazing SQL Community. It is quite possible that after creating a table, as you start using it, you may discover you've forgot to mention any column or constraint or specified a wrong name for the column. In this tutorial you will learn how to alter or modify an existing table using SQL.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |