dbTalk Databases Forums  

Oracle system table

comp.databases.oracle.server comp.databases.oracle.server


Discuss Oracle system table in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mounilk
 
Posts: n/a

Default Oracle system table - 07-28-2010 , 12:16 AM






Hi,
I am working on oracle database which has a few tables that do not
have any primary keys. Unfortunately, I cannot modify the table
designs.

I need to find out the fields in the table that make the record
unique.

I am not very familiar with Oracle and its system tables, but am
pretty sure I should be able to get this information from some system
table.

Any help is greatly appreciated.

Regards,
MounilK

Reply With Quote
  #2  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: Oracle system table - 07-28-2010 , 01:38 AM






On 28.07.2010 07:16, Mounilk wrote:
Quote:
Hi,
I am working on oracle database which has a few tables that do not
have any primary keys. Unfortunately, I cannot modify the table
designs.

I need to find out the fields in the table that make the record
unique.

I am not very familiar with Oracle and its system tables, but am
pretty sure I should be able to get this information from some system
table.

Any help is greatly appreciated.

Regards,
MounilK
You can achieve uniqueness in oracle by utilization of unique indexes or
unique constraints. To find them you can query
select * from user_indexes where uniqueness='UNIQUE'
resp.
select * from user_constraints where constraint_type = 'U'
After you have the names, you can drill down to columns - there are
user_ind_columns and user_cons_columns.
For all user_ views there are as well all_/dba_ which may be less/more
sutitable for your needs.


Best regards

Maxim

Reply With Quote
  #3  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: Oracle system table - 07-28-2010 , 07:18 AM



On Tue, 27 Jul 2010 22:16:44 -0700, Mounilk wrote:

Quote:
Hi,
I am working on oracle database which has a few tables that do not have
any primary keys. Unfortunately, I cannot modify the table designs.

I need to find out the fields in the table that make the record unique.

I am not very familiar with Oracle and its system tables, but am pretty
sure I should be able to get this information from some system table.

Any help is greatly appreciated.

Regards,
MounilK
Why would a RDBMS need to maintain a record of uniqueness? How would it
do that? Nope, there are tools which allow you to determine whether there
are duplicates and add unique constraints. RDBMS per se does not maintain
anything about the uniqueness of columns nor is it required to.



--
http://mgogala.byethost5.com

Reply With Quote
  #4  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Oracle system table - 07-28-2010 , 07:54 AM



On 28.07.2010 14:18, Mladen Gogala wrote:
Quote:
On Tue, 27 Jul 2010 22:16:44 -0700, Mounilk wrote:

I am working on oracle database which has a few tables that do not have
any primary keys. Unfortunately, I cannot modify the table designs.

I need to find out the fields in the table that make the record unique.

I am not very familiar with Oracle and its system tables, but am pretty
sure I should be able to get this information from some system table.

Any help is greatly appreciated.

Why would a RDBMS need to maintain a record of uniqueness? How would it
do that? Nope, there are tools which allow you to determine whether there
are duplicates and add unique constraints. RDBMS per se does not maintain
anything about the uniqueness of columns nor is it required to.
Adding to that: even if you find out which columns *currently* have
unique values per record (see below) this does not guarantee that it is
always the case. OP, the only real chance is to either investigate
uniqueness constraints or unique indexes as Maxim has indicated or find
out otherwise which columns are supposed to be unique (documentation,
application code, ask someone). But frankly, if there are columns in
the schema which are supposed to be unique but don't have appropriate
constraints then I'd question the schema design.

Note, if you want to find out the current state of affairs you can do
something like

select count(*) / count(distinct cola) as rows_per_val_cola
, count(*) / count(distinct colb) as rows_per_val_colb
....

Columns which turn up 1 are unique right now. But watch out for NULLS!
And be prepared that this is likely slow if your tables are big.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Reply With Quote
  #5  
Old   
Lothar Armbrüster
 
Posts: n/a

Default Re: Oracle system table - 07-28-2010 , 10:35 AM



Mounilk <mounilkadakia (AT) hotmail (DOT) com> writes:

Quote:
Hi,
I am working on oracle database which has a few tables that do not
have any primary keys. Unfortunately, I cannot modify the table
designs.

I need to find out the fields in the table that make the record
unique.

I am not very familiar with Oracle and its system tables, but am
pretty sure I should be able to get this information from some system
table.

Any help is greatly appreciated.

Regards,
MounilK
If you just need to identify a row to issue an update command, using the
rowid pseudocolumn may help. This is kind of implicid primary key. But
keep
in mind that rowids should *never* be stored in the database since they
are invalidated e.g. by export/import.

Hope that helps,
Lothar

--
Lothar Armbrüster | lothar.armbruester (AT) t-online (DOT) de
Hauptstr. 26 |
65346 Eltville |

Reply With Quote
  #6  
Old   
joel garry
 
Posts: n/a

Default Re: Oracle system table - 07-28-2010 , 12:18 PM



On Jul 27, 10:16*pm, Mounilk <mounilkada... (AT) hotmail (DOT) com> wrote:
Quote:
Hi,
I am working on oracle database which has a few tables that do not
have any primary keys. Unfortunately, I cannot modify the table
designs.

I need to find out the fields in the table that make the record
unique.
Ironically, as you may notice from the other replies, this is an
ambiguous question with no unique answer.

What exactly is your need? I work on a database that has many tables
with no primary keys, so the app makes assumptions...

Quote:
I am not very familiar with Oracle and its system tables, but am
pretty sure I should be able to get this information from some system
table.

Any help is greatly appreciated.

Regards,
MounilK
jg
--
@home.com is bogus.
http://www.cuddletech.com/blog/pivot/entry.php?id=1074

Reply With Quote
  #7  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: Oracle system table - 07-28-2010 , 09:32 PM



On Wed, 28 Jul 2010 10:18:03 -0700, joel garry wrote:

Quote:
What exactly is your need? I work on a database that has many tables
with no primary keys, so the app makes assumptions...
Having tables with no primary keys is usually a sign of poor design, and
therefore the application itself is extremely suspicious. When table is
created, there must be some kind of criteria for identifying the records
and selecting them from the table. That is what the primary keys are for.
There has been, as you're probably well aware, a long debate about
"natural" vs. "generated" (or "unnatural") primary key. Each approach has
its advantages but there must be a primary key for every table.


--
http://mgogala.byethost5.com

Reply With Quote
  #8  
Old   
joel garry
 
Posts: n/a

Default Re: Oracle system table - 07-29-2010 , 11:46 AM



On Jul 28, 7:32*pm, Mladen Gogala <gogala.mla... (AT) gmail (DOT) com> wrote:
Quote:
On Wed, 28 Jul 2010 10:18:03 -0700, joel garry wrote:
What exactly is your need? *I work on *a database that has many tables
with no primary keys, so the app makes assumptions...

Having tables with no primary keys is usually a sign of poor design, and
therefore the application itself is extremely suspicious. When table is
created, there must be some kind of criteria for identifying the records
and selecting them from the table. That is what the primary keys are for.
There has been, as you're probably well aware, a long debate about
"natural" vs. "generated" (or "unnatural") primary key. Each approach has
its advantages but there must be a primary key for every table.

--http://mgogala.byethost5.com
This may be an exception to the poor design suspicion, though I agree
with you that it normally would be. In this case, it is for
historical reasons - the app and programming language came out of the
early relational DEC world (Before RDB). In the early '80s, it was
common for software providers to write their own file routines. One
particular company wrote this relational software accessing its own
files, with a patent for getting any row in two disk accesses IIRC. I
first saw it at one of their customers in 1981. Later, they upgraded
the development tool to handle RMS files, then RDB files. Meanwhile,
they were bought by a series of companies, and eventually were
absorbed into a melange of app companies. In the early '90's, they
rewrote the tool to be able to handle multiple dbms engines, and
rewrote the apps. At this time, they were well aware of relational
design, as well as what customers needed, so in that sense it was well
designed. So think about how sophisticated primary keys were in the
Oracle 7.0 days, and its contemporaneous competitors. Anyways, the db-
blind tool had had an interesting, though arbitrary solution to
primary keys - whichever index was first alphabetically would be the
primary key. Of course, 20 years on this sounds stupid, but at the
time an app development tool could be far more relational than the
engines - and they did have RDB as their primary environment, using
the environment to catch other engines up to proper relational theory,
as well as allowing 3GL/4GL in the language - like all the stuff
people do in PL/SQL now (sometimes wrongly). In Oracle's case,
everything would be done by extracting rowid's and data. So you could
have automatic projections of how long reports will take to run,
report generators, and all that RAD stuff. It even worked with RMS
files up to a few years ago.

In the end, people like me wind up hearing about Agile and putting
everything in the app layer, and just roll our eyes.

But the apps themselves (now we're talking Enterprise level) have been
wrung out and improved, and are easily customizable for business
processes, and work really well for certain vertical markets (process
manufacturing in particular). Unfortunately, most Oracle customers
have either "stabilized" or moved to other players, most newer
customers just go MS and jam it all in. And the Chinese own it now -
a big part of their Oracle expansion in the '90s was because of NLS
and the eastern Pacific market.

jg
--
@home.com is bogus. "28. You walk into a grocery store, and see your
banks ATM machine being worked on. You see there is actually an
ordinary PC with an ordinary keyboard. On the screen is a SQL prompt,
and there is no one around. " - Me, 2003
http://www.informationweek.com/news/...Section=N ews

Reply With Quote
  #9  
Old   
Mark D Powell
 
Posts: n/a

Default Re: Oracle system table - 07-29-2010 , 12:21 PM



On Jul 28, 10:32*pm, Mladen Gogala <gogala.mla... (AT) gmail (DOT) com> wrote:
Quote:
On Wed, 28 Jul 2010 10:18:03 -0700, joel garry wrote:
What exactly is your need? *I work on *a database that has many tables
with no primary keys, so the app makes assumptions...

Having tables with no primary keys is usually a sign of poor design, and
therefore the application itself is extremely suspicious. When table is
created, there must be some kind of criteria for identifying the records
and selecting them from the table. That is what the primary keys are for.
There has been, as you're probably well aware, a long debate about
"natural" vs. "generated" (or "unnatural") primary key. Each approach has
its advantages but there must be a primary key for every table.

--http://mgogala.byethost5.com
As a historical note it used to be very common for vendor products to
not declare PK constraints in the database but to include unique
indexes on the tables. This was in part because some database
products did not support constraints and in part due to the menatality
of "if I have a unique index why do I need to declare a PK constraint
also". As mgogala said the application really should be using PK, UK,
and FK constraints.

As mentioned dba_indexes can be used to find indexes built with the
unique attribute and dba_ind_columns can be used to find the list of
columns that make up the index.

HTH -- Mark D Powell --

Reply With Quote
  #10  
Old   
Mounilk
 
Posts: n/a

Default Re: Oracle system table - 08-02-2010 , 01:28 AM



On Jul 30, 3:21*am, Mark D Powell <Mark.Powe... (AT) hp (DOT) com> wrote:
Quote:
On Jul 28, 10:32*pm, Mladen Gogala <gogala.mla... (AT) gmail (DOT) com> wrote:

On Wed, 28 Jul 2010 10:18:03 -0700, joel garry wrote:
What exactly is your need? *I work on *a database that has many tables
with no primary keys, so the app makes assumptions...

Having tables with no primary keys is usually a sign of poor design, and
therefore the application itself is extremely suspicious. When table is
created, there must be some kind of criteria for identifying the records
and selecting them from the table. That is what the primary keys are for.
There has been, as you're probably well aware, a long debate about
"natural" vs. "generated" (or "unnatural") primary key. Each approach has
its advantages but there must be a primary key for every table.

--http://mgogala.byethost5.com

As a historical note it used to be very common for vendor products to
not declare PK constraints in the database but to include unique
indexes on the tables. *This was in part because some database
products did not support constraints and in part due to the menatality
of "if I have a unique index why do I need to declare a PK constraint
also". *As mgogala said the application really should be using PK, UK,
and FK constraints.

As mentioned dba_indexes can be used to find indexes built with the
unique attribute and dba_ind_columns can be used to find the list of
columns that make up the index.

HTH -- Mark D Powell --
Hi All,
Thanks for your replies. I am a novice when it comes to Oracle db's,
pl-sql et al....I would appreciate if you can give me the query/
queries which i can run to find the information. I know it's kind of
spoonfeeding....but I'd appreaciate the help

Regards

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.