暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

华为GaussDB T TRUNCATE TABLE

墨天轮 2019-10-12
518

TRUNCATE TABLE

功能描述

删除表中所有的数据,释放表的存储空间。

注意事项

  • 用户可通过TRUNCATE TABLE语句删除表中所有的行。用户能清空自己表中的行;清空其他用户的表,需要DROP ANY TABLE权限。
  • TRUNCATE语句不能回滚。
  • 可以使用DELETE语句删除数据。
  • 数据库重启回滚期间不支持该操作。

语法格式

TRUNCATE TABLE [ schema_name. ]table_name [ PURGE ] [ { DROP | REUSE } STORAGE ]

参数说明

  • [schema_name.] table_name

    清空表名。

  • 不指定PURGE、DROP STORAGEREUSE STORAGE

    对表执行TRUNCATE操作后,表会放入回收站,可以通过FLASHBACK命令恢复。

  • PURGE

    和DROP STORAGE等价。

  • DROP STORAGE

    DROP STORAGE是默认值,回收清除表中rows的free space给tablespace,回收回来的free space可以供其它segment使用。

  • REUSE STORAGE

    不回收清除表中rows的free space给tablespace,这部分空间只能被自己用。

示例

删除表education的全部数据并回收清除表中记录的空闲空间。
--删除表education。 DROP TABLE IF EXISTS education;
--创建表education。 CREATE TABLE education(staff_id INT, higest_degree CHAR(8) NOT NULL, graduate_school VARCHAR(64), graduate_date DATETIME, education_note VARCHAR(70));
--向表education中插入记录1。 INSERT INTO education(staff_id,higest_degree,graduate_school,graduate_date,education_note) VALUES(10,'doctor','Xidian University','2017-07-06 12:00:00','211'); --向表education中插入记录2。 INSERT INTO education(staff_id,higest_degree,graduate_school,graduate_date,education_note) VALUES(11,'master','Northwestern Polytechnical University','2017-07-06 12:00:00','211&985'); --向表education中插入记录3。 INSERT INTO education(staff_id,higest_degree,graduate_school,graduate_date,education_note) VALUES(12,'scholar','Xi’an University of Architecture and Technology','2017-07-06 12:00:00','not 211 or 985'); --提交整个事务。 COMMIT;
--删除表education的全部数据并回收清除表中记录的空闲空间。 TRUNCATE TABLE education DROP STORAGE;
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论