Hi,
1. I have some table. But i do not know how to find primary key column, forign key column in that table. Is any procedure or function is available in oracle to find this?.
Thanks,
Srinivasan r
26 137836
Hi,
1. I have some table. But i do not know how to find primary key column, forign key column in that table. Is any procedure or function is available in oracle to find this?.
Thanks,
Srinivasan r
Hi,
This is the query to get a list of primary keys: -
SELECT * FROM ALL_CONS_COLUMNS A JOIN ALL_CONSTRAINTS C ON A.CONSTRAINT_NAME = C.CONSTRAINT_NAME WHERE C.TABLE_NAME = <your table> AND C.CONSTRAINT_TYPE = 'P'
-
And this is the query for foreign keys: -
SELECT * FROM ALL_CONS_COLUMNS A JOIN ALL_CONSTRAINTS C ON A.CONSTRAINT_NAME = C.CONSTRAINT_NAME WHERE C.TABLE_NAME = <your table> AND C.CONSTRAINT_TYPE = 'R'
-
Hi,
1. I have some table. But i do not know how to find primary key column, forign key column in that table. Is any procedure or function is available in oracle to find this?.
Thanks,
Srinivasan r
Hi,
The following query will give all the constraints specified on a table belonging to <owner_name> schema. -
SELECT *
-
FROM SYS.ALL_CONSTRAINTS A , SYS.ALL_CONS_COLUMNS B
-
WHERE S.OWNER=<owner_name> AND S.TABLE_NAME=<table_name> AND A.CONSTRAINT_NAME=B.CONSTRAINT_NAME
-
You can further filter this based upon the constraint type you are interested in. For primary key constraint, include CONSTRAINT_TYPE ='P' in the WHERE clause. For foreign key constraint, include CONSTRAINT_TYPE ='R' in the WHERE clause.
Hi ,
To correct Chandu. you should also have the owner name.
So code becomes -
SELECT * FROM ALL_CONS_COLUMNS A JOIN ALL_CONSTRAINTS C ON A.CONSTRAINT_NAME = C.CONSTRAINT_NAME WHERE C.TABLE_NAME = <your table> AND C.CONSTRAINT_TYPE = 'R' and C.OWNER='<OWNER NAME>'
-
Cheers
Hi,
This is the query to get a list of primary keys: -
SELECT * FROM ALL_CONS_COLUMNS A JOIN ALL_CONSTRAINTS C ON A.CONSTRAINT_NAME = C.CONSTRAINT_NAME WHERE C.TABLE_NAME = <your table> AND C.CONSTRAINT_TYPE = 'P'
-
And this is the query for foreign keys: -
SELECT * FROM ALL_CONS_COLUMNS A JOIN ALL_CONSTRAINTS C ON A.CONSTRAINT_NAME = C.CONSTRAINT_NAME WHERE C.TABLE_NAME = <your table> AND C.CONSTRAINT_TYPE = 'R'
-
Yes..You will have to add one more filter on the OWNER as the same table names can be used across users. Thks for pointing it out Frozen.
If you want only the column names you can use
SELECT C.COLUMN_NAME, C.POSITION instead of SELECT *
Position is helpful when you have composite keys.
Hi,
Fine. It is working.
What is that table ALL_CONSTRAINTS and ALL_CONS_COLUMN S.
Whether it is System table or anyother?
Thanks,
Srinivasan r
Hi,
Fine. It is working.
What is that table ALL_CONSTRAINTS and ALL_CONS_COLUMN S.
Whether it is System table or anyother?
Thanks,
Srinivasan r
These are system views present in SYS schema.
Hi,
Just now i see it..
What is the difference between Views and Tables. Anything advantage by using Views? When should we use Views?
Thanks..
Srinivasan r
It was quite useful...
Thanks to everyone.
Cheer.
cPiyush.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Robert Brown |
last post by:
Let's say I have a type hierarchy: (just an example)
the general entity customer:
CREATE TABLE customer(customer_id int, customer_name varchar(250),
customer_type int)
three specific customer subtypes: 1 - business, 2 - home, 3 -
university
|
by: pb648174 |
last post by:
I have a table called BidItem which has another table called
BidAddendum related to it by foreign key. I have another table called
BidFolder which is related to both BidItem and BidAddendum, based on a
column called RefId and one called Type, i.e. type 1 is a relationship
to BidItem and type 2 is a relationship to BidAddendum.
Is there any...
|
by: D. Dante Lorenso |
last post by:
I'd like to run a clean up command on my tables to
eliminate rows that I'm no longer using in the database.
I want to do something like this:
DELETE FROM tablename
WHERE IS_REFERENCED_BY_FOREIGN_KEY IS FALSE;
Does anyone know how something like this could be done
in PostgreSQL? I know I can search all the tables that
|
by: Ross A. Finlayson |
last post by:
Hi,
I'm scratching together an Access database. The development box is
Office 95, the deployment box Office 2003.
So anyways I am griping about forms and global variables. Say for
example I'm adding a customer. The Customer fields are mostly foreign
keys that refer to primary keys in other tables, left join instead of
junction tables...
|
by: Thomas T. Thai |
last post by:
I'm looking for a better way to make use of foreign keys. Here is a
sample setup:
-- TESTING Foreign Keys
create table mod (
mod_id int not null primary key,
name varchar(32) not null default ''
);
| |
by: sonal |
last post by:
Hi all,
I hv started with python just recently... and have been assigned to
make an utility which would be used for data validations...
In short we take up various comma separated data files
for eg: area.txt, school.txt, students.txt.... and so on (ok?!?)
now,
1. area code used in the school.txt must be defined in the area.txt
(Primary key...
|
by: ravichoudhari |
last post by:
i came accross requirement of multiple foreign keys in a table
referencing the same primary key another table. i created the table
relations using the relations editor in access. even though i could
have multiple foreign keys to a table access did allow the referential
integrity.
my database structure is
table1 - students table
table 2...
|
by: Wolfgang Keller |
last post by:
Hello,
so far it seems to me as if the only ORM module for Python which
supports composite primary/foreign keys was SQLAlchemy. Which looks a
little bit "overbloated" for my needs: I "just" need to be able to
define a "logical model" (à la UML) in Python and have the ORM connect
to a database (running on PostgreSQL in my case) which uses a...
|
by: JnrJnr |
last post by:
I have two SQL database tables. One contains various products(with unique primary keys) and the other contains information related to the products aswel as the product's foreign keys.
What I want to do is first get all the foreign keys(using SQL queries/select statements) and "store" them so that I can then, according to those foreign keys, get...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |