Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2006
    Posts
    20

    Unanswered: 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?

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

  3. #3
    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.

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

  5. #5
    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.

  6. #6
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •