Use DROP TABLE statement to delete any existing table in MySQL database. This deletes all table data and structure both. Syntax: DROP TABLEtable_name; Example – MySQL Drop Table For example, I have table users in the database. I need to remove its data completely with structure. Login to your MySQL server and select database. Now execute below query to remove the database. DROP TABLE users;
Read MoreTag: table
MySQL – Truncate Table
Use MySQL TRUNCATE TABLE statement to delete all table content. This doesn’t remote table structure. The truncate table also reset the auto increment values. Syntax: TRUNCATE TABLE table_name MySQL Truncate Table Statement For example to remove all data from table named users use following command. You must select database first before running below command.
1 | mysql> TRUNCATE TABLE users; |
Example – MySQL Truncate Table For example, I have a table named users with following records in a database. First, check the available data in the table. After that truncate table and again check.
1 2 3 4 5 6 7 8 9 | mysql> SELECT * FROM users; +----+-----------+-----------------+--------------------+---------------------+--------+ | ID | username | password | email | signup_date | status | +----+-----------+-----------------+--------------------+---------------------+--------+ | 1 | admin | $P$BXq.6qP/fAtg | rahul@example.com | 2017-11-04 19:11:53 | 1 | +----+-----------+-----------------+--------------------+---------------------+--------+ | 2 | tecadmin | $P$Kxn3.s8KD/39 | hello@example.com | 2017-11-03 07:37:07 | 0 | +----+-----------+-----------------+--------------------+---------------------+--------+ 2 row in set (0.01 sec) |
…
Read MoreMySQL – Create Table
Use CREATE TABLE statement to create a new table in MySQL database. You must create and select a database to create tables in it. Syntax: CREATE TABLE [IF NOT EXISTS] table_name ( coloumn1, coloumn2 ) engine=table_type; Here [IF NOT EXISTS] is used to create table only if there are no existing table with the name. The database engine can be used as per your requirements. A column can be defined as following. column_name data_type[size] [NOT NULL|NULL] [DEFAULT value] [AUTO_INCREMENT], Example: For example, create table users to store information of our…
Read More