sql 截断表命令_SQL截断,删除或重命名表

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 截断表命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值