Book a Demo

Author Topic: Any way to change name of Oracle sequence?  (Read 5192 times)

walter_sung

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Any way to change name of Oracle sequence?
« on: March 21, 2006, 06:44:08 pm »
When exporting DDL for an Oracle table is it possible specify the name of a Sequence, or the associated Trigger for an auto-numbered field?



jaimeglz

  • EA User
  • **
  • Posts: 164
  • Karma: +0/-0
    • View Profile
Re: Any way to change name of Oracle sequence?
« Reply #1 on: March 21, 2006, 08:41:31 pm »
Hi Walter,

Hopefully, others will contribute a simpler solution on this topic; but, in my experience, sequences are totally independent of the tables, and should be modelled as such. For example, you can create a special package called "Sequences" in the package that contains your table's definition in your model. Since each table and it's corresponding sequence are independent from one another, there is nothing in Oracle that could directly tell a CASE tool that a sequence is tied to a table. (If you do model your seqs, I would suggest to create a <<dependency>> or a <<call>> relationship between each table and it's corresponding sequence in the diagram, so as to keep track of what seq belongs to what table.)

Please note that modelling sequences is not essential.

What can solve your code gen problem, however, is to include the CREATE SEQUENCE code together with (and just before) the trigger's code as one of the table's operations: create a new operation (say, tdb_cat_key), stereotype it as "trigger", copy or write your trigger's code into the operation's "Behaviour" tab, and have EA include both the CREATE SEQUENCE and CREATE TRIGGER code in the DDL:

CREATE SEQUENCE seq_cat
MINVALUE 0
START WITH 0
INCREMENT BY 1
NOCYCLE
NOCACHE
;
-- Won't work if it is not initialized
SELECT seq_cat.NEXTVAL
FROM dual;
-- Create the trig
CREATE OR REPLACE TRIGGER tdb_cat_key
BEFORE INSERT ON t_cat FOR EACH ROW
BEGIN
SELECT seq_cat.NEXTVAL INTO :new.cat_key FROM dual;
END tdb_cat_key;
/

When generating your DDL, and having selected the option to generate the trig, you will see this operation's code in the generated code. The seq and the trig will now be generated together with your table.

Hope it works for you as well as it has worked for me.

Jaime
« Last Edit: March 22, 2006, 06:08:40 am by jaimeglz »

walter_sung

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Any way to change name of Oracle sequence?
« Reply #2 on: March 21, 2006, 09:28:32 pm »
Thanks for your solution Jaime,

I have been using the built in Auto-number functionality on tables in EA by selecting the Auto-number option in the Column Properties.

This method is convenient, but does not show the Sequence or the Trigger in the Operations dialog for the table (presumably because this method of handling auto-numbering fields is not supported by all DBMS platforms).

Do I have to code the triggers/sequences manually?
(I would prefer to leave this type of task to the code generator, especially since I only want to rename them).