Hi all,
Here I share some useful information in sql queries like truncate command, drop command alter command. These is more helpful in MYSQL operations.
For delete complete data from an existing table using TRUNCATE command. And also delete the data inside the table.
For delete a table using DROP command. It helps to remove all table definition and all data, indexes of the corresponding table.
For rename the table by using rename command.
TRUNCATE COMMAND
The SQL truncate command is used for delete all the data from an existing table. TRUNCATE table is similar to DELETE command in sql with no where clause.
SYNTAX
TRUNCATE TABLE table_name
Here is an Example explaining it.
truncate table Employee;
The above query will delete all the records of Employee table. Delete complete data from Employee table.
DROP COMMAND
The SQL DROP command is used for completely removes a table from database. This command also destroy the table struncture also. It is used to remove a table definition and all data, indexes, triggers, constraints, and permission specifications for that table.
SYNTAX
drop table table_name
Here is an Example explaining it.
drop table Employee;
The above query will delete the Employee table completely. The drop helps to remove all the employee table data.
The DROP command can also be used on Databases.
SYNTAX
drop database database_name;
Here is an Example explaining it.
drop database Organization;
The above query will drop a database named Organization from the system.
RENAME COMMAND
The rename command is used to rename a table.
SYNTAX
rename table old-table-name to new-table-name
old-table-name:Specifies the name of the table to be renamed.
new-table-name:Specifies the new name of the table.
Here is an Example explaining it.
rename table Employee to Employee_details;
The above query will rename Employee table to Employee_details. The old table name is Emplyess rename as new table name Employee_details
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.