Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

query to find keys in a table

Posted on 2012-04-11
5
366 Views
Last Modified: 2012-06-27
hi

i have this query which tells what are the primary keys in a table

SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
FROM all_constraints cons, all_cons_columns cols
WHERE cols.table_name = 'PERSON_DATA'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
ORDER BY cols.table_name, cols.position;

Any one care to explain what are the tables : all_constraints and all_cons_columns
and what is cons.constraint_type = 'P'

Thanks
0
Comment
Question by:royjayd
  • 2
  • 2
5 Comments
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 100 total points
ID: 37833393
>>all_constraints
>>all_cons_columns
>>cons.constraint_type = 'P'

All of this is in the docs:
http://docs.oracle.com/cd/E11882_01/server.112/e25513/statviews_1046.htm

http://docs.oracle.com/cd/E11882_01/server.112/e25513/statviews_1044.htm
0
 

Author Comment

by:royjayd
ID: 37833409
slightwv

A simple one or two liners with a layman explanation would have helped :-)
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37833421
I'm not sure I could have explained it better than the docs do.
0
 
LVL 32

Accepted Solution

by:
awking00 earned 200 total points
ID: 37833483
all_constraints and all_cons_columns are system dictionay views containing metadata of the database. The all_ prefix allows you to get information on objects that you own or have access to (the dba_ prefix is for all objects and the user_prefix is only for objects you own).
The constraint_type values available are:
C - Check constraint on a table
P - Primary key
U - Unique key
R - Referential integrity
V - With check option, on a view
O - With read only, on a view
H - Hash expression
F - Constraint that involves a REF column
S - Supplemental logging

Some additional links -
http://psoug.org/reference/constraints.html
http://docs.oracle.com/cd/B28359_01/server.111/b28320/statviews_1042.htm
0
 

Author Comment

by:royjayd
ID: 37837505
thanks.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
selective queries 7 37
Shredding xml into an oracle 11g Database 2 58
oracle forms question 22 39
Toad 12.10 Enterprise visual interface 4 20
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question