GET SEQUENCE NAME FOR A TABLE.

hello everyone.
i have a question regarding to get the sequence name pertaining to a table.
say for example i have a table "Employee" with columns "eid",ename,ecity.
if eid is the primary key and i made it a auto increment sequence with name of sequence as "eid_seq"

how would i get the sequence name eid_seq using a query.

in general,if  i pass in a tablename and tableowner i should get sequence name for that table.

i hvae tried using user_dependencies and to get triggers and associate triggers with sequences.but my problem was what if you have more than 1 trigger?? how would you deal that??

is there any other way to do it?

any help is appreciated.
thanks
Pgnath.
pgnathAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ishandoCommented:
There is no direct relationship between a table and a sequence built into the database. Any relationship that exists between them is created by you.

One approach would be to have a standard naming convention for you sequences, e.g. <colname>_seq or <tab>_<col>_seq so that you can easily generate the sequence name programatically if you need to.

An alternative would be to add a comment to the sequenced column, which is the name of the associated sequence, and then you can retrieve the sequence name from the all_col_comments view.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pgnathAuthor Commented:
hi ishando
i do have the naming conventions ,and i did think of the process.but i was thinking if there is any generic way to do this.i do appreciate your suggestion.

as i said there is other way to approach to use user_dependency and get triggers associated and the find the sequence using the trigger.

infact here is my query
SELECT REFERENCED_NAME into tblSeq1
FROM USER_DEPENDENCIES
WHERE NAME = (SELECT NAME FROM USER_DEPENDENCIES A,USER_TRIGGERS B
WHERE TYPE = 'TRIGGER' and B.TRIGGERING_EVENT='INSERT' AND REFERENCED_OWNER = tblOwner AND REFERENCED_NAME = tblName)
AND REFERENCED_OWNER = tblOwner AND REFERENCED_TYPE = 'SEQUENCE';

this wont work if u have more than 1 trigger in a table.so u need to loop through then find out sequence associated.

thanks
Pgnath.
0
ishandoCommented:
but do you have multiple sequences per table?

if not then you can simply do:

SELECT distinct REFERENCED_NAME into tblSeq1
FROM USER_DEPENDENCIES
....


0
alexnuijtenCommented:
Why would you want to do it a "generic" way? There are going to be exceptions whatever you can come up with in a generic way.

Simply create a before insert row trigger to fill your Primary Key with the next-value from the sequence and you're set. You can make a template for this type of trigger and use this over and over whenever you create a new table. You can also create a "Generator" to create the trigger for you..

Alex
0
pgnathAuthor Commented:
i didnt get any defnitive answer for my question.
ok i would share teh points for the two people who gave their efforts
thanks
pgnath
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.