473,499 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problems creating tables inside a stored procedure

1 New Member
I am generating upgrade/new install scripts for my project. I am able to do this in oracle and sql server but an running into problems in db2. What I am trying to do is to use some logic to only create table that have not been generated in prevous releases. I am trying to create a stored procedure to do this.
I am not able to create the stored procedure because it errors out with the error below. I am stumped as how to get around this error because the errorr is happening when I am creating the stored procedure and not when I am executing.

ERROR [42710] [IBM][DB2/NT] SQL0601N The name of the object to be created is identical to the existing name "MIKEBO.TBLROLES" of type "TABLE". LINE NUMBER=11. SQLSTATE=42710

here is the base test procedure with one table

CREATE PROCEDURE CREATETABLE
(
)
SPECIFIC CreateTable
LANGUAGE SQL
BEGIN
DECLARE table_count INTEGER 0;

select COUNT(*) INTO table_count from syscat.tables where tabname = 'TBLROLES';
IF( table_count=0) THEN
CREATE TABLE "TBLROLES" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (
START WITH +1
INCREMENT BY +1
MINVALUE +1
MAXVALUE +2147483647
NO CYCLE
CACHE 20
NO ORDER ) ,
"ROLENAME" VARGRAPHIC(10) NOT NULL ,
"AUTHDESCRIPTION" VARGRAPHIC(50),
PRIMARY KEY ("ID"),
CONSTRAINT "IX_TBLROLES" UNIQUE ("ROLENAME"))
IN "USERSPACE1" ;
END IF;
END;
Feb 15 '07 #1
1 6335
mersis
2 New Member
I am having exactly the same problem. I need to drop and recreate same stored procedure from time to time. And in the stored procedure I test if a table does not exist I create it. If it does, I drop it and then create a new one. But when I try to recreate the stored proc second time after some tables have already been created by the previous stored proc, creation fails.

Did you find a way to turn that stupid check (that is unable to see that I am actually droping the tables before creating them if they exist) to make the creation of a stored to continue?

Would be great to hear if you have solved this problem somehow (other than using dynamic SQL, which is very ugly).

Thanks

I am generating upgrade/new install scripts for my project. I am able to do this in oracle and sql server but an running into problems in db2. What I am trying to do is to use some logic to only create table that have not been generated in prevous releases. I am trying to create a stored procedure to do this.
I am not able to create the stored procedure because it errors out with the error below. I am stumped as how to get around this error because the errorr is happening when I am creating the stored procedure and not when I am executing.

ERROR [42710] [IBM][DB2/NT] SQL0601N The name of the object to be created is identical to the existing name "MIKEBO.TBLROLES" of type "TABLE". LINE NUMBER=11. SQLSTATE=42710

here is the base test procedure with one table

CREATE PROCEDURE CREATETABLE
(
)
SPECIFIC CreateTable
LANGUAGE SQL
BEGIN
DECLARE table_count INTEGER 0;

select COUNT(*) INTO table_count from syscat.tables where tabname = 'TBLROLES';
IF( table_count=0) THEN
CREATE TABLE "TBLROLES" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (
START WITH +1
INCREMENT BY +1
MINVALUE +1
MAXVALUE +2147483647
NO CYCLE
CACHE 20
NO ORDER ) ,
"ROLENAME" VARGRAPHIC(10) NOT NULL ,
"AUTHDESCRIPTION" VARGRAPHIC(50),
PRIMARY KEY ("ID"),
CONSTRAINT "IX_TBLROLES" UNIQUE ("ROLENAME"))
IN "USERSPACE1" ;
END IF;
END;
Jun 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
6035
by: Lili | last post by:
I'm having problems creating a simple stored procedure in DB2. Can someone help? Here is the screen dump when I tried to load the stored procedure. Thanks for any help. Create procedure...
1
1790
by: Paul | last post by:
Hi, I wish to be able to add tables to a sql server database at runtime from my asp.net application. As well as creating fields I also wish to be able to create indexes on selected fields and to...
8
1911
by: Mauricio | last post by:
Hello, Currently we have an ASP.NET 2003 app running, on one function the app calls to a stored procedure to SQLServerONE, that stored procedure creates some TEMP tables with the results of a...
2
1730
by: =?Utf-8?B?SXbDoW4gU2Fpbno=?= | last post by:
I ran the aspnet_regsql.exe tool with the -sqlexportonly option to create the script. I searched and replace the string by and had the dba's run the script. When I do anything like...
9
9296
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger,...
1
3024
by: birundha | last post by:
Hi Hope this will help more peolpe... We got a new design where we use Global temporary tables(GTT) inside stored procedure... My question is can we use GTT inside a stored procedure and...
1
1059
by: Roobmeister | last post by:
I have a script that builds multiple tables and then builds tables from those tables, etc.. Usually, I run the script as a DTS package, and it doesn't have any problems. However, when I save the...
5
4054
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...
2
1745
by: Andrew Cooper | last post by:
Greetings, I'm creating a website using ASP.NET. In creating my DAL I've got a Table Adapter that I've set up to use an existing Stored Procedure from an SQL Server 2000 database. However,...
0
7012
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...
0
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7392
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.