Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2794630
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: DB2/Informix

2014-12-19 15:41:16

Posted on by Joachim Selke

The SQL standard defines a TRUNCATE TABLE command, which deletes all data contained in a table. Unfortunately, does not support this command yet (version 9.5). Strangely, it is in since version 9.1.

UPDATE: Version 9.7 finally introduced the command.

Below you find three ways to simulate the behavior of TRUNCATE TABLE tablename on DB2 LUW.

Option 1: ALTER TABLE

ALTER TABLE tablename ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE

The documentation describes this operation as follows:

Causes all data currently in table to be removed. Once the data has been removed, it cannot be recovered except through use of the RESTORE facility. If the unit of work in which this alter statement was issued is rolled back, the table data will not be returned to its original state.

When this action is requested, no DELETE triggers defined on the affected table are fired. Any indexes that exist on the table are also deleted.

 

 

Option 2: IMPORT

IMPORT FROM /dev/null OF DEL REPLACE INTO tablename

In contrast to Option 1, this operation is . Note that on Windows systems, you have to replace /dev/null by NUL.

 

 

Option 3: DELETE

DELETE FROM tablename

This usually is very slow, so options 1 and 2 are to be preferred.

阅读(3164) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~