473,385 Members | 2,003 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.

how to drop table and drop related views/functions etc...

Hi all,

When i try to drop a table, and this table have (for example) some
function related...db2 don't allow to drop the table

how can i enter a command to drop the table AND all the objects
(functions...triggers...views) that depends on that table?

A.M.

Jan 4 '07 #1
8 6610
Alessandro,

When checking dependencies, would it be enough to check only below
catalog tables:

SYSCAT.INDEXDEP
SYSCAT.PACKAGEDEP
SYSCAT.ROUTINEDEP
SYSCAT.TABDEP

Am I missing any other db2 objects?

BTW: I don't think such a drop command exists b/c of circular & self
referencing complications. They need to be resolved delicately.

Regards,

Mehmet Baserdem

Jan 4 '07 #2
Mehmet Baserdem wrote:
Alessandro,

When checking dependencies, would it be enough to check only below
catalog tables:

SYSCAT.INDEXDEP
SYSCAT.PACKAGEDEP
SYSCAT.ROUTINEDEP
SYSCAT.TABDEP

Am I missing any other db2 objects?

BTW: I don't think such a drop command exists b/c of circular & self
referencing complications. They need to be resolved delicately.
You can use the SYSPROC.DB2LK_DEP_OF() table function.
It's undocumented, but the arguments are self explanatory.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Jan 4 '07 #3

Serge Rielau wrote:
[...]
BTW: I don't think such a drop command exists b/c of circular & self
referencing complications. They need to be resolved delicately.
You can use the SYSPROC.DB2LK_DEP_OF() table function.
It's undocumented, but the arguments are self explanatory.
Thats nifty. But shouldnt it work for all kinda objects? I tried the
following:

create function tmp.test1() returns int return 3;
create function tmp.test2() returns int return values tmp.test1();

thus test2 is dependent of test1. But neither:

DB2LK_DEP_OF('F',TMP','TEST1'), DB2LK_DEP_OF('F',TMP','TEST2'), nor
using the specificname returns a row.

I noticed that DB2LK_DEP_OF invokes DB2LK_DEP_FIRST, and the part that
handles functions looks like:

SELECT 'F', T1.ROUTINESCHEMA, T1.ROUTINENAME, T2.SPECIFICNAME,
T2.DEFINER, T2.CREATE_TIME
FROM SYSCAT.ROUTINEDEP T1, SYSCAT.ROUTINES T2
WHERE T1.BTYPE = 'F'
AND T1.BSCHEMA = 'TMP'
AND T1.ROUTINESCHEMA = T2.ROUTINESCHEMA
AND T1.ROUTINENAME = T2.ROUTINENAME
;

but that join does not work because of:

SELECT ROUTINESCHEMA , ROUTINENAME
FROM SYSCAT.ROUTINEDEP
WHERE ROUTINESCHEMA = 'TMP';

ROUTINESCHEMA
ROUTINENAME
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
TMP

SQL070104223111900
1 record(s) selected.
SELECT ROUTINESCHEMA , ROUTINENAME
FROM SYSCAT.ROUTINES
WHERE ROUTINESCHEMA = 'TMP';

ROUTINESCHEMA
ROUTINENAME
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
TMP
TEST1
TMP
TEST2
That is, ROUTINENAME in SYSCAT.ROUTINES is different from ROUTINENAME
in SYSCAT.ROUTINEDEP

If the join is changed to:

SELECT 'F', T1.ROUTINESCHEMA, T1.ROUTINENAME, T2.SPECIFICNAME,
T2.DEFINER, T2.CREATE_TIME
FROM SYSCAT.ROUTINEDEP T1, SYSCAT.ROUTINES T2
WHERE T1.BTYPE = 'F'
AND T1.BSCHEMA = 'TMP'
AND T1.ROUTINESCHEMA = T2.ROUTINESCHEMA
AND T1.ROUTINENAME = T2.SPECIFICNAME
;

it seems to work:

1 ROUTINESCHEMA
ROUTINENAME

SPECIFICNAME

DEFINER

CREATE_TIME
-
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
--------------------------
F TMP

SQL070104224459500

SQL070104224459500
DB2INST1

2007-01-04-22.44.59.521521

1 record(s) selected.
It looks like a bug, but I'm not convinced that I understand how it
should work.

[db2inst1@ft-05 ~]$ db2level
DB21085I Instance "db2inst1" uses "32" bits and DB2 code release
"SQL08026"
with level identifier "03070106".
Informational tokens are "DB2 v8.1.2.120", "s060801", "MI00163", and
FixPak
"13".
Product is installed at "/opt/IBM/db2/V8.1".

[db2inst1@ft-05 ~]$ uname -a
Linux ft-05 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686
i686 i386 GNU/Linux

/Lennart

Jan 4 '07 #4
Lennart wrote:
Serge Rielau wrote:
[...]
>>BTW: I don't think such a drop command exists b/c of circular & self
referencing complications. They need to be resolved delicately.
You can use the SYSPROC.DB2LK_DEP_OF() table function.
It's undocumented, but the arguments are self explanatory.
Thats nifty. But shouldnt it work for all kinda objects? I tried the
following:
... the initial version I wrote was meant to be extensible. Don't recall
whether it was changed since then....
create function tmp.test1() returns int return 3;
create function tmp.test2() returns int return values tmp.test1();
What is it with VALUES? I see a lot of unnecessary usage of VALUES, is
there some book that's spreading this coding style?
RETURN tmp.test1() should work just fine...
VALUES actually produces a table, making RETURN VALUES .. a scalar
subquery...
thus test2 is dependent of test1. But neither:

DB2LK_DEP_OF('F',TMP','TEST1'), DB2LK_DEP_OF('F',TMP','TEST2'),
Ok, this should definitely not work. You need the specific name for sure
nor using the specificname returns a row.

I noticed that DB2LK_DEP_OF invokes DB2LK_DEP_FIRST, and the part that
handles functions looks like:

SELECT 'F', T1.ROUTINESCHEMA, T1.ROUTINENAME, T2.SPECIFICNAME,
T2.DEFINER, T2.CREATE_TIME
FROM SYSCAT.ROUTINEDEP T1, SYSCAT.ROUTINES T2
WHERE T1.BTYPE = 'F'
AND T1.BSCHEMA = 'TMP'
AND T1.ROUTINESCHEMA = T2.ROUTINESCHEMA
AND T1.ROUTINENAME = T2.ROUTINENAME
<snip>
That is, ROUTINENAME in SYSCAT.ROUTINES is different from ROUTINENAME
in SYSCAT.ROUTINEDEP

If the join is changed to:

SELECT 'F', T1.ROUTINESCHEMA, T1.ROUTINENAME, T2.SPECIFICNAME,
T2.DEFINER, T2.CREATE_TIME
FROM SYSCAT.ROUTINEDEP T1, SYSCAT.ROUTINES T2
WHERE T1.BTYPE = 'F'
AND T1.BSCHEMA = 'TMP'
AND T1.ROUTINESCHEMA = T2.ROUTINESCHEMA
AND T1.ROUTINENAME = T2.SPECIFICNAME
;
<snip>
It looks like a bug, but I'm not convinced that I understand how it
should work.
I think you are correct. That is a bug.

I'll follow up. In the meantime any potential consumer can create their
own variety.
>
[db2inst1@ft-05 ~]$ db2level
DB21085I Instance "db2inst1" uses "32" bits and DB2 code release
"SQL08026"
with level identifier "03070106".
Informational tokens are "DB2 v8.1.2.120", "s060801", "MI00163", and
FixPak
"13".
Product is installed at "/opt/IBM/db2/V8.1".

[db2inst1@ft-05 ~]$ uname -a
Linux ft-05 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686
i686 i386 GNU/Linux

/Lennart

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Jan 5 '07 #5

Serge Rielau wrote:
[...]
What is it with VALUES? I see a lot of unnecessary usage of VALUES, is
there some book that's spreading this coding style?
I actually tested it with an existing function first, but needed
something simpler for an example. Did not put to much thought into the
function though. But, if it is a problem that people use values this
way it might be caused by how the function is fully declared:

CREATE FUNCTION ... ()
RETURNS INT
LANGUAGE SQL
....

3 is not a valid SQL stmt (at least I don't think it is), and if one
tries to be a good citizen (:-) one might be fooled to use a valid sql
stmt in there.
RETURN tmp.test1() should work just fine...
VALUES actually produces a table, making RETURN VALUES .. a scalar
subquery...
Does the values clause cause any overhead? I could not resist checking
out my functions. None of them returned a scalar constant, so I'm just
curious.
>
thus test2 is dependent of test1. But neither:

DB2LK_DEP_OF('F',TMP','TEST1'), DB2LK_DEP_OF('F',TMP','TEST2'),
Ok, this should definitely not work. You need the specific name for sure
Yep, that figures. Just wanted to make sure by including this as well.

[...]
That is, ROUTINENAME in SYSCAT.ROUTINES is different from ROUTINENAME
in SYSCAT.ROUTINEDEP
While I'm at it (I fully understand that it is not possible to change
the schema, just reflecting), the name of the column in
SYSCAT.ROUTINEDEP seems wrong. It would make more sense if it where
named SPECIFICNAME. I guess that is what fooled you in the first place?

[...]
>
I'll follow up. In the meantime any potential consumer can create their
own variety.
Definitely, I have been thinking about creating such a function for
some time, and this will certainly make a nice start.

For the wish list: it would be nice if the function returned
VISUAL_NAME as well as OBJECTNAME. For tables and such they would be
the same, but for PROCEDURES, FUNCTIONS and such, both MY_PROCEDURE and
P4183825 where returned.

Just some thoughts, keep up the good work
/Lennart

Jan 5 '07 #6

Serge Rielau wrote:
[...]
What is it with VALUES? I see a lot of unnecessary usage of VALUES, is
there some book that's spreading this coding style?
I actually tested it with an existing function first, but needed
something simpler for an example. Did not put to much thought into the
function though. But, if it is a problem that people use values this
way it might be caused by how the function is fully declared:

CREATE FUNCTION ... ()
RETURNS INT
LANGUAGE SQL
....

3 is not a valid SQL stmt (at least I don't think it is), and if one
tries to be a good citizen (:-) one might be fooled to use a valid sql
stmt in there.
RETURN tmp.test1() should work just fine...
VALUES actually produces a table, making RETURN VALUES .. a scalar
subquery...
Does the values clause cause any overhead? I could not resist checking
out my functions. None of them returned a scalar constant, so I'm just
curious.
>
thus test2 is dependent of test1. But neither:

DB2LK_DEP_OF('F',TMP','TEST1'), DB2LK_DEP_OF('F',TMP','TEST2'),
Ok, this should definitely not work. You need the specific name for sure
Yep, that figures. Just wanted to make sure by including this as well.

[...]
That is, ROUTINENAME in SYSCAT.ROUTINES is different from ROUTINENAME
in SYSCAT.ROUTINEDEP
While I'm at it (I fully understand that it is not possible to change
the schema, just reflecting), the name of the column in
SYSCAT.ROUTINEDEP seems wrong. It would make more sense if it where
named SPECIFICNAME. I guess that is what fooled you in the first place?

[...]
>
I'll follow up. In the meantime any potential consumer can create their
own variety.
Definitely, I have been thinking about creating such a function for
some time, and this will certainly make a nice start.

For the wish list: it would be nice if the function returned
VISUAL_NAME as well as OBJECTNAME. For tables and such they would be
the same, but for PROCEDURES, FUNCTIONS and such, both MY_PROCEDURE and
P4183825 where returned.

Just some thoughts, keep up the good work
/Lennart

Jan 5 '07 #7
Lennart wrote:
>
Serge Rielau wrote:
[...]
>What is it with VALUES? I see a lot of unnecessary usage of VALUES, is
there some book that's spreading this coding style?

I actually tested it with an existing function first, but needed
something simpler for an example. Did not put to much thought into the
function though. But, if it is a problem that people use values this
way it might be caused by how the function is fully declared:

CREATE FUNCTION ... ()
RETURNS INT
LANGUAGE SQL
...

3 is not a valid SQL stmt (at least I don't think it is), and if one
tries to be a good citizen (:-) one might be fooled to use a valid sql
stmt in there.
Right, 3 is not a SQL statement. It is an expression. But "RETURN 3" is a
valid statement as is "RETURN function()"
>RETURN tmp.test1() should work just fine...
VALUES actually produces a table, making RETURN VALUES .. a scalar
subquery...

Does the values clause cause any overhead? I could not resist checking
out my functions. None of them returned a scalar constant, so I'm just
curious.
Another question would be: given that VALUES is unnecessarily used quite
often as Serge says, couldn't the optimizer or query rewrite "just" remove
it in such cases?

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Jan 5 '07 #8

Knut Stolze wrote:
[...]
Right, 3 is not a SQL statement. It is an expression. But "RETURN 3" is a
valid statement as is "RETURN function()"
Just to avoid confusion, I'm not saying that it is the case, nor that
it is a correct conclusion. I'm just speculating over what might be the
cause for Serges observations.

/Lennart

Jan 5 '07 #9

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

Similar topics

1
by: Sabrina | last post by:
Hi everybody, I need some help in SQL Server. I am looking for a command that will "Drop all user table" in a user database. Can anyone help me? Thank you very much Sabrina
3
by: David Link | last post by:
Hi All, Here's a Conditional drop_table func for those interested. There was a thread on this a long time back. We do this all the time : DELETE TABLE sales; CREATE TABLE sales (...);
10
by: BuddhaBuddy | last post by:
Platform is DB2/NT 7.2.9 The table was created like this: CREATE TABLE MYTEST ( MYTESTOID bigint not null primary key, FK_OTHEROID bigint not null references other, FK_ANOTHEROID bigint not...
20
by: Ed | last post by:
I am running Access 2002 and just ran the built in Access wizard for splitting a database into a back end (with tables) and front end (with queries, forms, modules, etc.). After running the...
3
by: phil | last post by:
We are developing specs. for a website for a nonprofit org, with database for membership related functions. But..question is regarding drop down menu links. We will have 20 category-pages, and...
4
by: Gregor Kovač | last post by:
Hi! Is it possible do to something like this: DROP TABLE MY_TABLE ONLY IF EXISTS and the same for views, indexes, procedures, .... ? Best regards, Kovi --...
14
by: maya | last post by:
I need a drag-n-drop script.. I have found one here.. http://javascript.internet.com/page-details/drag-n-drop.html each div containing an image has an id, and each image has a name, as in ...
15
by: uwcssa | last post by:
I try to drop a table as: I got: During SQL processing it returned: SQL0478N The object type "TABLE" cannot be dropped because there is an object "sch.SQL070515104729271", of type "FUNCTION",...
2
by: Query Builder | last post by:
Hi, I have transactional replication set up on on of our MS SQL 2000 (SP4) Std Edition database server Because of an unfortunate scenario, I had to restore one of the publication databases. I...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.