sql 截断表命令
In this tutorial we will learn about the various DDL commands which are used to re-define the tables.
在本教程中,我们将学习用于重新定义表的各种DDL命令。
TRUNCATE
命令 (TRUNCATE
command)
TRUNCATE
command removes all the records from a table. But this command will not destroy the table's structure. When we use TRUNCATE
command on a table its (auto-increment) primary key is also initialized. Following is its syntax,
TRUNCATE
命令从表中删除所有记录。 但是此命令不会破坏表的结构。 当我们在表上使用TRUNCATE
命令时,其(自动递增)主键也会被初始化。 以下是其语法,
TRUNCATE TABLE table_name
Here is an example explaining it,
这是一个解释它的例子,
TRUNCATE TABLE student;
The above query will delete all the records from the table student.
上面的查询将从表student中删除所有记录。
In DML commands, we will study about the DELETE
command which is also more or less same as the TRUNCATE
command. We will also learn about the difference between the two in that tutorial.
在DML命令中,我们将研究DELETE
命令,该命令也与TRUNCATE
命令大致相同。 我们还将在该教程中了解两者之间的区别。
DROP
命令 (DROP
command)
DROP
command completely removes a table from the database. This command will also destroy the table structure and the data stored in it. Following is its syntax,
DROP
命令从数据库中完全删除一个表。 此命令还将破坏表结构及其中存储的数据。 以下是其语法,
DROP TABLE table_name
Here is an example explaining it,
这是一个解释它的例子,
DROP TABLE student;
The above query will delete the Student table completely. It can also be used on Databases, to delete the complete database. For example, to drop a database,
上面的查询将完全删除Student表。 它也可以在数据库上使用,以删除整个数据库。 例如,要删除数据库,
DROP DATABASE Test;
The above query will drop the database with name Test from the system.
上面的查询将从系统中删除名称为Test的数据库。
RENAME
查询 (RENAME
query)
RENAME
command is used to set a new name for any existing table. Following is the syntax,
RENAME
命令用于为任何现有表设置新名称。 以下是语法,
RENAME TABLE old_table_name to new_table_name
Here is an example explaining it.
这是一个解释它的例子。
RENAME TABLE student to students_info;
The above query will rename the table student to students_info.
上面的查询会将表student重命名为students_info 。
翻译自: https://www.studytonight.com/dbms/truncate-drop-rename-query.php
sql 截断表命令