473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

TRUNCATE TABLE really exists, or?

Hello,

Until this date, I believed that DB2 has no TRUNCATE TABLE command. But
then I came across
http://publib.boulder.ibm.com/infoce...c/c0023297.htm
where it says:

After an ALTER TABLE statement containing
REORG-recommended operations, you can execute
only the following statements on a table:
REORG TABLE
DROP TABLE
ALTER TABLE
RENAME TABLE
TRUNCATE TABLE

So there _is_ a TRUNCATE TABLE command, or?
My DB2 Express-C v. 9.1 will NOT accept a "TRUNCATE TABLE foo" command.

--
Regards,
Troels Arvin <tr****@arvin.dk>
http://troels.arvin.dk/
Jan 31 '07 #1
10 13858
Troels Arvin wrote:
Until this date, I believed that DB2 has no TRUNCATE TABLE command. But
then I came across
http://publib.boulder.ibm.com/infoce...c/c0023297.htm
where it says:

After an ALTER TABLE statement containing
REORG-recommended operations, you can execute
only the following statements on a table:
REORG TABLE
DROP TABLE
ALTER TABLE
RENAME TABLE
TRUNCATE TABLE
Doc defect... don't loose your faith just yet.
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 1 '07 #2
On Jan 31, 3:13 pm, Troels Arvin <tro...@arvin.dkwrote:
Hello,

Until this date, I believed that DB2 has no TRUNCATE TABLE command. But
then I came acrosshttp://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2....
where it says:

After an ALTER TABLE statement containing
REORG-recommended operations, you can execute
only the following statements on a table:
REORG TABLE
DROP TABLE
ALTER TABLE
RENAME TABLE
TRUNCATE TABLE

So there _is_ a TRUNCATE TABLE command, or?
My DB2 Express-C v. 9.1 will NOT accept a "TRUNCATE TABLE foo" command.

--
Regards,
Troels Arvin <tro...@arvin.dk>http://troels.arvin.dk/
Hi, Troels:

This is somewhat well-known, so forgive me if you already know it, but
if it happens that you're looking not for the TRUNCATE command per se
but rather in the meantime a way to accomplish the same thing in the
absence of an explicit TRUNCATE command, in DB2 there are two ways to
get the same result of fast cleanout of all rows in a table:

1. ALTER TABLE <NOT LOGGED INITIALLY WITH EMPTY TABLE;
2. IMPORT from /dev/null

Regards,

--Jeff

Feb 1 '07 #3
Hello,

On Thu, 01 Feb 2007 10:12:59 -0800, jefftyzzer wrote:
a way to accomplish the same thing in the
absence of an explicit TRUNCATE command, in DB2 there are two ways to
get the same result of fast cleanout of all rows in a table:

1. ALTER TABLE <NOT LOGGED INITIALLY WITH EMPTY TABLE;
2. IMPORT from /dev/null
Which one requires the least privileges?

--
Regards,
Troels Arvin <tr****@arvin.dk>
http://troels.arvin.dk/
Feb 1 '07 #4
On Feb 1, 11:42 am, Troels Arvin <tro...@arvin.dkwrote:
Hello,

On Thu, 01 Feb 2007 10:12:59 -0800, jefftyzzer wrote:
a way to accomplish the same thing in the
absence of an explicit TRUNCATE command, in DB2 there are two ways to
get the same result of fast cleanout of all rows in a table:
1. ALTER TABLE <NOT LOGGED INITIALLY WITH EMPTY TABLE;
2. IMPORT from /dev/null

Which one requires the least privileges?

--
Regards,
Troels Arvin <tro...@arvin.dk>http://troels.arvin.dk/
According to the SQL Reference Volume 2 and the Command Reference,
respectively:

ALTER needs at least one of the following:

ALTER on the table to be altered
CONTROL on the table to be altered
ALTERIN on the schema of the table
SYSADM
DBADM

IMPORT (to an existing table using the REPLACE or REPLACE_CREATE
option) requires one of the following:

SYSADM
DBADM
CONTROL on the table or view
INSERT, SELECT, and DELETE on the table or view

So I suppose IMPORT requires the least privileges, if you are generous
in giving INSERT, SELECT, and DELETE.

--Jeff

Feb 1 '07 #5
Hello,

On Thu, 01 Feb 2007 12:19:09 -0800, jefftyzzer wrote:
According to the SQL Reference Volume 2 and the Command Reference,
respectively:
[...]

Thanks. My summary:
http://troels.arvin.dk/db/rdbms/#bul...cate_table-db2

--
Regards,
Troels Arvin <tr****@arvin.dk>
http://troels.arvin.dk/
Feb 1 '07 #6
On Feb 1, 2:51 pm, Troels Arvin <tro...@arvin.dkwrote:
Hello,

On Thu, 01 Feb 2007 12:19:09 -0800, jefftyzzer wrote:
According to the SQL Reference Volume 2 and the Command Reference,
respectively:

[...]

Thanks. My summary:http://troels.arvin.dk/db/rdbms/#bul...cate_table-db2

--
Regards,
Troels Arvin <tro...@arvin.dk>http://troels.arvin.dk/
Nice work--very useful!

--Jeff

Feb 2 '07 #7
Hello,

On Thu, 01 Feb 2007 10:12:59 -0800, jefftyzzer wrote:
in DB2 there are two ways to
get the same result of fast cleanout of all rows in a table:

1. ALTER TABLE <NOT LOGGED INITIALLY WITH EMPTY TABLE;
2. IMPORT from /dev/null
Is there a performance difference between these two approaches?

--
Regards,
Troels Arvin <tr****@arvin.dk>
http://troels.arvin.dk/
Feb 2 '07 #8
Troels Arvin wrote:
Hello,

On Thu, 01 Feb 2007 10:12:59 -0800, jefftyzzer wrote:
>in DB2 there are two ways to
get the same result of fast cleanout of all rows in a table:

1. ALTER TABLE <NOT LOGGED INITIALLY WITH EMPTY TABLE;
2. IMPORT from /dev/null

Is there a performance difference between these two approaches?
Not that I'm aware of, but option 2 is fully recoverable.
If you truncate an important table using ALTER TABLE you should follow
it up with a backup, otherwise roll forward recovery will hiccup.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 2 '07 #9
On Fri, 02 Feb 2007 08:43:35 -0500, Serge Rielau wrote:
>>1. ALTER TABLE <NOT LOGGED INITIALLY WITH EMPTY TABLE;
2. IMPORT from /dev/null

Is there a performance difference between these two approaches?
Not that I'm aware of, but option 2 is fully recoverable.
If you truncate an important table using ALTER TABLE you should follow
it up with a backup, otherwise roll forward recovery will hiccup.
Ouch. I'll stay away from ALTER TABLE ... NOT LOGGED INITIALLY. (I've
recently been bit by a rather time consuming situation because we tried to
cut some corners using NOT LOGGED INITIALLY.)

--
Regards,
Troels Arvin <tr****@arvin.dk>
http://troels.arvin.dk/
Feb 2 '07 #10
Ian
Serge Rielau wrote:
Doc defect... don't loose your faith just yet.
Dang! Is it a defect in that the doc was updated too soon? ;-)

Feb 3 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ed | last post by:
I am trying to get some information to compare and contrast the Truncate Table function and the Drop Table function. I know that using Truncate Table is faster and saves the structure of the table...
3
by: martin | last post by:
Hi, We have a heavily used production server and a table which logs every hit on a web site. This table has grown large over time and we want to clear it down as efficiently as possible. We would...
3
by: LineVoltageHalogen | last post by:
Greeting All, I have a stored proc that dynamically truncates all the tables in my databases. I use a cursor and some dynamic sql for this: ...... create cursor Loop through sysobjects and...
5
by: ronin 47th | last post by:
Hi group, In one of the books 'Gurus Guide to Transact SQL' i found this info: ------------------------------------------------------------ TRUNCATE TABLE empties a table without logging row...
2
by: rdraider | last post by:
Hi, I am trying to create a script that deletes transaction tables and leaves master data like customer, vendors, inventory items, etc. How can I use TRUNCATE TABLE with an Exists? My problem is...
2
by: Neil | last post by:
Can one use Truncate Table on a linked server table? When I try it, I get a message that only two prefixes are allowed. Here's what I'm using: Truncate Table svrname.dbname.dbo.tablename
8
by: bob | last post by:
I am writing some code to create new tables in a SQL database. However, I don't want to try to create a table if it already exists. How can I test beforehand to see if a particular named table...
14
by: Sala | last post by:
Hi I want to truncate all data in database ... pls help me how i ll truncate?
2
by: Boogha | last post by:
I have a cursor looping through a list of tables that I want to truncate and then do a bulk insert into, Is this possible in SQL Server 2000 or do script each table individually. Cheers, Adam
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.