Home » SQL & PL/SQL » SQL & PL/SQL » How to find Sequences associated to a table (ORACLE 11g)
How to find Sequences associated to a table [message #614832] Tue, 27 May 2014 12:48 Go to next message
gorants
Messages: 85
Registered: May 2014
Location: ATL
Member
Hello All,

How do we find sequences associated to a table.

Ex : In EMP table emp_id is primary key it will get incremented from sequnece , how do i know which sequence was get used by EMP table.

thanks
Re: How to find Sequences associated to a table [message #614833 is a reply to message #614832] Tue, 27 May 2014 12:50 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
There is no such thing.

A sequence is a stand alone object. You can use it in a table, you can use it in many tables, you can use it in tables in other schemas, or you can choose not to use it.

[addendum]
What I am saying is that you need to look at your application code. there is nothing in any oracle table that has this information.

[Updated on: Tue, 27 May 2014 12:51]

Report message to a moderator

Re: How to find Sequences associated to a table [message #614834 is a reply to message #614832] Tue, 27 May 2014 12:52 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Bad, very bad design. I have never seen such a thing. Primary key being a sequence, why?
Re: How to find Sequences associated to a table [message #614836 is a reply to message #614834] Tue, 27 May 2014 12:56 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
> In EMP table emp_id is primary key it will get incremented from sequnece , how do i know which sequence was get used by EMP table.
look at TRIGGER code associated with EMP table
Re: How to find Sequences associated to a table [message #614838 is a reply to message #614834] Tue, 27 May 2014 12:58 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Lalit Kumar B wrote on Tue, 27 May 2014 18:52
Bad, very bad design. I have never seen such a thing. Primary key being a sequence, why?
Lalit, surely you have made mistake. Primary keys are what sequences are for.
--update:
think about a 12c identity column. Sequence created implicitly.

[Updated on: Tue, 27 May 2014 13:00]

Report message to a moderator

Re: How to find Sequences associated to a table [message #614839 is a reply to message #614836] Tue, 27 May 2014 12:59 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
@BS, a trigger sufficing a primary key?
Re: How to find Sequences associated to a table [message #614841 is a reply to message #614839] Tue, 27 May 2014 13:09 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Lalit Kumar B wrote on Tue, 27 May 2014 10:59
@BS, a trigger sufficing a primary key?

YES, SEQUENCE used to populate PK is done frequently by some.
Re: How to find Sequences associated to a table [message #614842 is a reply to message #614834] Tue, 27 May 2014 13:10 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Lalit Kumar B wrote on Tue, 27 May 2014 19:52
Bad, very bad design. I have never seen such a thing. Primary key being a sequence, why?


You never saw that?
So what is the main purpose of sequence if this is not that?

Re: How to find Sequences associated to a table [message #614843 is a reply to message #614839] Tue, 27 May 2014 13:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Lalit Kumar B wrote on Tue, 27 May 2014 19:59
@BS, a trigger sufficing a primary key?


A trigger providing primary key, yes!
A sequence is one of the best way to get a primary key when data does not provide a clear one or a too long one.

Re: How to find Sequences associated to a table [message #614849 is a reply to message #614843] Tue, 27 May 2014 13:29 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Folks, sorry about it. Was into some other world. Didn't realize that its the base table, I by mistake considered it to be a derived table using a relationship. Sorry again, need black coffee to overcome it, too late for me to focus.
Re: How to find Sequences associated to a table [message #614854 is a reply to message #614832] Tue, 27 May 2014 14:55 Go to previous message
EdStevens
Messages: 1376
Registered: September 2013
Senior Member
As others have said, there is no inherent relationship. Since use of a sequence to populate a PK column (or any other possible use, for that matter) is an application issue you need to consider everywhere such code could reside.

Ideally it would be in an ON INSERT trigger
but it could also be in an INSERT statement in any pl/sql or java code in the database
or it could be in an INSERT statement embedded in application code that resides OUTSIDE the database.

My point is that while there are some 'best practices' to help locate it, there are no guarantees. Worst case is the reference to the sequence could even be in a little sql script sitting on someones local desktop machine up in the accounting department. Also there could be some INSERT statements that use the sequence, and some other code somewhere else (like the guy in Accounting) that also does an insert on the table and does NOT use the sequence.

[Updated on: Tue, 27 May 2014 14:55]

Report message to a moderator

Previous Topic: Insert into Partition Tables After Column Addition
Next Topic: use of SQL Hints "RESULT CACHE"
Goto Forum:
  


Current Time: Wed Apr 24 20:36:49 CDT 2024