If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > conditional expression

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-06, 08:26
dhuygu dhuygu is offline
Registered User
 
Join Date: Sep 2006
Posts: 20
conditional expression

Code:
ALTER TABLE MALZEME.KATEGORILER ALTER COLUMN ID DROP IDENTITY ;
EXPORT TO "D:\PROGRA~1\IBM\SQLLIB\WEBCPTAB.IXF" OF IXF MESSAGES 
"D:\PROGRA~1\IBM\SQLLIB\WEBCPTAB.EXM" SELECT * FROM MALZEME.KATEGORILER;
CONNECT TO PERSONEL;
IMPORT FROM "D:\PROGRA~1\IBM\SQLLIB\WEBCPTAB.IXF" OF IXF MESSAGES 
"D:\Program Files\IBM\SQLLIB\copy.txt" CREATE INTO MALZEME.KATEGORILER IN USERSPACE1;
I copied a table which has auto-generated identity as I wrote above.
But I want to write conditional expression like this:
if given table's column's identity is 'Y'
alter (drop identity)
export
import
alter (addd identity)
else
export
import

How can I write this?
Reply With Quote
  #2 (permalink)  
Old 09-27-06, 11:09
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Exactly what are you trying to accomplish? It looks like you are exporting from the table that has the identity column but that is all you are doing to it. Why drop the identity at all?

Also what DB2 version and OS?

Andy
Reply With Quote
  #3 (permalink)  
Old 09-27-06, 14:37
dhuygu dhuygu is offline
Registered User
 
Join Date: Sep 2006
Posts: 20
in my application I copy all tables of selected database.So automatically it must control if a table has auto -generate identity before exporting and importing.
I wnt write sql commands to do it.I can copy the tables by db2 commands but I dont know how to add this condition to my commands.
Reply With Quote
  #4 (permalink)  
Old 09-27-06, 14:58
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
First, please supply your DB2 version and OS.

I still do not understand what the purpose of this is. You example shows exporting out of the source DB and creating the table on the destination DB from the export ixf. If all you are doing is exporting from a table on the source DB then there is not need to do anything about identity columns for that table on the source DB. You are just reading rows.

Andy
Reply With Quote
  #5 (permalink)  
Old 09-27-06, 16:44
dhuygu dhuygu is offline
Registered User
 
Join Date: Sep 2006
Posts: 20
while exporting you are true.there is no need to drop auto-generate identity.
rows are read and export.
But while importing if you dont drop this identity rows are rejected.You can nopy the table structure with import command but not data.
Reply With Quote
  #6 (permalink)  
Old 09-27-06, 16:54
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
OK. You can do either of these.

On the destination tables, instead of creating the identity columns as "GENERATE ALWAYS" you can set then to "GENERATE BY DEFAULT".

Or you could do it your way. You can identify the identity columns from syscat.columns where tabname = ? and identity = 'Y'.

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On