473,385 Members | 1,309 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 tables in stored procs?

I know that we can use import or load to truncate tables without
filling up trans log in DB2. Is it possible to do this in a stored
procedure? How about in CLI/C++? My impression is that import/load
are not SQL statements, hence may not be included in stored procs or
called from CLI. Is that correct? I tried to use import/load in a
stored proc and they were rejected as syntax errors.

If it is the case, we'd have only one option, that is, to call the
import/load commands from command line. I'd be surprised if this is
true since it is such a useful feature, and I hope there is a way
around?

Thanks!
Oct 13 '08 #1
3 3994
Henry J. wrote:
I know that we can use import or load to truncate tables without
filling up trans log in DB2. Is it possible to do this in a stored
procedure? How about in CLI/C++? My impression is that import/load
are not SQL statements, hence may not be included in stored procs or
called from CLI. Is that correct? I tried to use import/load in a
stored proc and they were rejected as syntax errors.

If it is the case, we'd have only one option, that is, to call the
import/load commands from command line. I'd be surprised if this is
true since it is such a useful feature, and I hope there is a way
around?
You can use the ADMIN_CMD() procedure to invoke LOAD or IMPORT through SQL.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Oct 13 '08 #2
On Oct 13, 2:53*pm, Serge Rielau <srie...@ca.ibm.comwrote:
Henry J. wrote:
I know that we can use import or load to truncate tables without
filling up trans log in DB2. *Is it possible to do this in a stored
procedure? *How about in CLI/C++? * My impression is that import/load
are not SQL statements, hence may not be included in stored procs or
called from CLI. *Is that correct? *I tried to use import/load in a
stored proc and they were rejected as syntax errors.
If it is the case, we'd have only one option, that is, to call the
import/load commands from command line. *I'd be surprised if this is
true since it is such a useful feature, and I hope there is a way
around?

You can use the ADMIN_CMD() procedure to invoke LOAD or IMPORT through SQL.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Thanks Serge. Some more questions:

1. Can I do "call admin_cmd()" in CLI/C++ as well?
2. I haven't tried using LOAD to truncate tables. Wonder what's the
best way to use LOAD for this purpose (I mean the syntax)?
3. If a column in the table is served as the foreign key of a child
table, as I know the IMPORT command will not work even if the child
table is empty. Will LOAD work?

Thanks!
Oct 14 '08 #3
Henry J. wrote:
1. Can I do "call admin_cmd()" in CLI/C++ as well?
Yes, that's the advantage of SQL statements they work everywhere.
2. I haven't tried using LOAD to truncate tables. Wonder what's the
best way to use LOAD for this purpose (I mean the syntax)?
Look for the REPLACE option in the syntax diagram
3. If a column in the table is served as the foreign key of a child
table, as I know the IMPORT command will not work even if the child
table is empty. Will LOAD work?
Yes LOAD will work. You will need to follow up with a SET INTEGRITY
statement.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Oct 14 '08 #4

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

Similar topics

1
by: db55 | last post by:
I have some users that I need to run stored procedures, but they can't seem to run them unless they are in the db_owner role of the database. How do I give them access to run the stored procs...
6
by: Dave | last post by:
1) I know that we can define an external proc to be Fenced or NotFenced on "CREATE PROCEDURE" command. I don't see the FENCED / NOT FENCED option on "Create Procedure" for SQL stored procs. Is...
1
by: Paul R | last post by:
Hi, I have a Winforms application that access some SQLServer2000 stored procedures. I have now written some new Webforms pages to use some of the same stored procs. The Webforms use the SAME...
5
by: Rob | last post by:
Using VB.net and Sql Server.... In general, should you try to use stored procedures for all updates ?
1
by: kentk | last post by:
Is there a difference in how SQL Server 7 and SQL 2000 processes SQL passed from a program by an ADO command object. Reason I ask is I rewrote a couple applications a couple years ago were the SQL...
15
by: Burt | last post by:
I'm a stored proc guy, but a lot of people at my company use inline sql in their apps, sometimes putting the sql in a text file, sometimes hardcoding it. They don't see much benefit from procs, and...
2
by: Andy B | last post by:
Is there an easy way to convert tableAdaptor queries into stored procs without messing up the dataTables in the dataSet or losing the queries themselves?
8
by: Frank Calahan | last post by:
I've been looking at LINQ and it seems very nice to be able to make queries in code, but I use stored procs for efficiency. If LINQ to SQL only works with SQL Server and stored procs are more...
5
by: Bogdan | last post by:
Hi, I have a stored procedure that uses JOINs to return columns from multiple tables. I also have another stored proc that that takes a series of params and updates multiple tables. I used the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.