Display the foreign keys and primary keys in hirarchy qeury please ?
Any sql query to get the following columns:
I should display all the master table names,it's primary key field and its foregin key field,the name of the foreignkey'table.
This should be displayed in hirarchy i.e. it should start from the top level table like upside down tree.
can we query the database like this
thanx in advance
prasanth a.s.
hi there,
Please can any body help in this query!
Thanxs in advance
prasanth a.s.
Similar Messages
-
Difference between Unique key and Primary key(other than normal difference)
Hello,
1).Can any one tell me any other difference between Unique key and Primary key other than it having NULLs.
2). What is the difference the words 'DISTINCT' and 'UNIQUE' in a sql query.
Thanks in advance.Hi
If you don't believe me than see the documentation in
OTN.
Ott Karesz
http://www.trendo-kft.hu
SQL> create table scott.tbl_clob
2 (sss CLOB)
3 /
Tabelle wurde angelegt.
SQL> insert into scott.tbl_clob values('wrwrwrw')
2 /
1 Zeile wurde erstellt.
SQL> insert into scott.tbl_clob values('wrwrwrw')
2 /
1 Zeile wurde erstellt.
SQL> select distinct sss from scott.tbl_clob
2 /
select distinct sss from scott.tbl_clob
FEHLER in Zeile 1:
ORA-00932: nicht übereinstimmende Datentypen
SQL> select unique sss from scott.tbl_clob
2 /
select unique sss from scott.tbl_clob
FEHLER in Zeile 1:
ORA-00932: nicht übereinstimmende Datentypen
SQL> select distinct to_char(sss) from scott.tbl_clob
2 /
TO_CHAR(SSS)
wrwrwrw
SQL> select unique to_char(sss) from scott.tbl_clob
2 /
TO_CHAR(SSS)
wrwrwrw
SQL> -
Diff b/w surragate keys and primary keys
Can any one of u pls explain the difference between primary key and surragate keys,pls explain me with simple example
Hi rajesh,
surrogate key: For every master data record, system create a SID (Surrogate ID). If that particular master data record is used in infocube, system store the SID corresponding to that master data in dimension table and the dimension id of the dimension table is stored in infocube Fact 'F' table.
Primary key: while creating a table we will select unique field and create as primary key..for eg empid acts as a unique key (primary key) for emp table. through this primary key we can identify the table to get the data from the table.
i hope this helps u.
regards
anil -
Null in Composite Primary Key and "Primary keys must not contain null"
Hello all.
I'm a newbie concerning to JPA/EJB3, but I was wondering if toplinks doesn't support composite primary keys with null in some field (something perfectly right in any RDBMS).
I used JDeveloper (I'm using Oracle 10g database and JDeveloper 10.1.3.2.) wizards to generate JPA classes and I checked out generated files (with annotations), so they should be right (by the way, other O-R mappings for my model are working right, but this one).
I'm getting the next error:
Exception Description: The primary key read from the row [DatabaseRecord(
TSUBGRUPOSLDI.CD_GRUP => 01
TSUBGRUPOSLDI.CD_SUBGRUP => null
TSUBGRUPOSLDI.CG_POBL => 058
TSUBGRUPOSLDI.CG_PROV => 28
TSUBGRUPOSLDI.DSCR => Sanidad)] during the execution of the query was detected to be null. Primary keys must not contain null.
Compound primary key is (CD_GRUP, CD_SUBGRUP). No foreign keys, no joins (only a NamedQuery: "select o from ..."). It's the simplest case!
I checked out that everything runs ok if there's no "null" value in CD_SUBGRUP.
After some research (this and other forums) I'm beginning to believe that it's not supported, but not sure.
Am I doing sth wrong? If not, what is the reason to not support this? Will it be supported in the future?
Thanks in advance.Null is a special value and in many databases is not comparable to another null value (hence the isNull operator) and may pose problems when used to uniquely identify an Entity. TopLink does not support null values within a composite PK. As the nullable column is most likely not designated as a PK within your database table (many databases do not allow this) I recommend updating the Entity PKs to match that of the database.
--Gordon -
Hi
When I am trying to define Update Key which is the other name for Alternate Key, then the primary key symbol (key) which is defined just beside my primary key column ( customer id) gets dissappeared and the new key symbol comes up besides the update key columns("marital status,salary and address")
Now why this happens and how to tackle.
In my project Customer id is a primary key which is responsible for insert of new records if not already presnt in the target table and the three other fields "marital status,salary and address" columns are responsible for update but these are not primary or composite keys.Can anyone tell me the difference in terms of how oracle update mechanism work in both the case.Not sure what you're asking.
Have you done an explain plan for each statement? -
Primary Key and Chronological Key for Time Dimension
Could someone please shed light whether it's better to use normal PK or Calendar Date (which is a chronological key on the most detailed level). I tried both and haven't noticed any difference. But my understanding is that I still need to have the PK key on the most detailed level in time hierarchy.
ThanksMatt,
the PK of the Time Dimension is a regular sequence numeric key. I have it defined as a logical PK for the dimension. However, I guess I was talking about hierarchy key. I tested it either way and the query time is the same. So I guess it doesn't really matter.
--------Year
Year (chronological key and primary key)
------------------Quarter
Quarter (key)
Quarter+Year (primary key, chronological key)
---------------------------------Day Detail
PK (key)
Date (primary key , chronological key)
I hope it makes sense. -
column with unique constraint + not null constraint = primary key! (to some extent) Is it correct?
I invite your ideashttp://www.techonthenet.com/oracle/unique.php
http://www.allapplabs.com/interview_questions/db_interview_questions.htm#q13
Difference between Unique key and Primary key(other than normal difference) -
Update Record Wizard, tng_Recordset and Primary Key
Hi - trying to make an image gallery that allows the user to add captions to each image displayed in a loop without having to send the user to a different form/detail page.
My question is - can the tng_recordset generated by the Update Record Wizard be modified to use a field of another recordset on the same page as it's primary key?
I.e. (on the Update Record behaviour) - Primary Key = Entered Value = {imagegalleries.galleryimages}
this doesn't work, but it's where I'd like to be...
The recordset 'imagegalleries' has been filtered using a URL variable that was defined as the gallery being edited.
Hope this makes sense - have been trying for days on this.
Dan-------
I just get a blank page
this means you´re having a PHP syntax error somewhere, and I´d recommend to always activate PHP error reporting at least on your local development server to have PHP indicate the reason why things aren´t working.
However, when using such native PHP syntax within this context, you´ll usually need to add some more stuff around the variable -- means:
$upd_boomcms_galleries_files->setPrimaryKey("bcms_galleryimage_id", "NUMERIC_TYPE", "VALUE", "".$row_galleryimagelist['bcms_galleryimage_id']."");
works better now ?
Cheers,
Günter Schenk
Adobe Community Expert, Dreamweaver -
Diff b/w primary key and unique key?
what is the diff b/w primary key and unique key?
Hi,
With respect to functionality both are same.
But in ABAP we only have Primary key for the Database tables declared in the Data Dictionary.
Unique is generally is the term used with declaring key's for internal tables.
Both primary and Unique keys can identify one record of a table.
Regards,
Sesh -
Difference between primary key and primary index
Dear All,
Hi... .Could you pls tell me the difference between primary key and primary index.
Thanks...Hi,
Primary Key : It is one which makes an entry of the field unique.No two distinct rows in a table can have the same value (or combination of values) in those columns.
Eg: first entry is 111, if you again enter value 111 , it doesnot allow 111 again. similarly for the strings or characters or numc etc. Remember that for char or numc or string 'NAME' is not equal to 'name'.
Primary Index: this is related to the performance .A database index is a data structure that improves the speed of operations in a table. Indices can be created using one or more columns, providing the basis for both rapid random lookups and efficient ordering of access to records. The disk space required to store the index is typically less than the storage of the table (since indices usually contain only the key-fields according to which the table is to be arranged, and excludes all the other details in the table), yielding the possibility to store indices into memory from tables that would not fit into it. In a relational database an index is a copy of part of a table. Some databases extend the power of indexing by allowing indices to be created on functions or expressions. For example, an index could be created on upper(last_name), which would only store the uppercase versions of the last_name field in the index.
In a database , we may have a large number of records. At the time of retrieving data from the database based on a condition , it is a burden to the db server. so whenever we create a primary key , a primary index is automatically created by the system.
If you want to maintain indices on other fields which are frequently used in where condition then you can create secondary indices.
Reward points if helpful.
Thanks,
Sirisha.. -
Difference between PRIMARY KEY and UNIQUE KEY with NOT NULL
What is the difference between PRIMARY KEY and UNIQUE KEY with NOT NULL constraint?
Message was edited by:
Nilesh HoleAnswer for the master!!!
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:8743855576462
Thanks,
Karthick -
Is there any restriction on the length of all Primary keys in a table
Hi all,
Is there any restriction on the length of all Primary keys in a data base table?
i have some 10 fields as primary key in a DB table and length exceeds 120 and getting a warning.
Please let me know will there be any problems in future with respect to the same?
With regards,
SumanthWell actually there are constraints like
Total of internal lengths of all primary key columns 1024 Bytes
Number of primary key columns per table 512
For other information about SAP database please refer to http://sapdb.org/sap_db_features.htm
Thanks & Regards,
Vivek Gaur
Alwayz in high spirits -
Dynamic SQL Joining between tables and Primary keys being configured within master tables
Team , Thanks for your help in advance !
I'm looking out to code a dynamic SQL which should refer Master tables for table names and Primary keys and then Join for insertion into target tables .
EG:
INSERT INTO HUB.dbo.lp_order
SELECT *
FROM del.dbo.lp_order t1
where not exists ( select *
from hub.dbo.lp_order tw
where t1.order_id = t2.order_id )
SET @rows = @@ROWCOUNT
PRINT 'Table: lp_order; Inserted Records: '+ Cast(@rows AS VARCHAR)
-- Please note Databse names are going to remain the same but table names and join conditions on keys
-- should vary for each table(s) being configured in master tables
Sample of Master configuration tables with table info and PK Info :
Table Info
Table_info_ID Table_Name
1 lp_order
7 lp__transition_record
Table_PK_Info
Table_PK_Info_ID Table_info_ID PK_Column_Name
2 1 order_id
8 7 transition_record_id
There can be more than one join condition for each table
Thanks you !
Rajkumar YeluguHi Rajkumar,
It is glad to hear that you figured the question out by yourself.
There's a flaw with your while loop in your sample code, just in case you hadn't noticed that, please see below.
--In this case, it goes to infinite loop
DECLARE @T TABLE(ID INT)
INSERT INTO @T VALUES(1),(3),(2)
DECLARE @ID INT
SELECT @ID = MIN(ID) FROM @T
WHILE @ID IS NOT NULL
PRINT @ID
SELECT @ID =ID FROM @T WHERE ID > @ID
So a cursor would be the appropriate option in your case, please reference below.
DECLARE @Table_Info TABLE
Table_info_ID INT,
Table_Name VARCHAR(99)
INSERT INTO @Table_Info VALUES(1,'lp_order'),(7,'lp__transition_record');
DECLARE @Table_PK_Info TABLE
Table_PK_Info_ID INT,
Table_info_ID INT,
PK_Column_Name VARCHAR(99)
INSERT INTO @Table_PK_Info VALUES(2,1,'order_id'),(8,7,'transition_record_id'),(3,1,'order_id2')
DECLARE @SQL NVarchar(MAX),
@ID INT,
@Table_Name VARCHAR(20),
@whereCondition VARCHAR(99)
DECLARE cur_Tabel_Info CURSOR
FOR SELECT Table_info_ID,Table_Name FROM @Table_Info
OPEN cur_Tabel_Info
FETCH NEXT FROM cur_Tabel_Info
INTO @ID, @Table_Name
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @whereCondition =ISNULL(@whereCondition+' AND ','') +'t1.'+PK_Column_Name+'='+'t2.'+PK_Column_Name FROM @Table_PK_Info WHERE Table_info_ID=@ID
SET @SQL = 'INSERT INTO hub.dbo.'+@Table_Name+'
SELECT * FROM del.dbo.'+@Table_Name+' AS T1
WHERE NOT EXISTS (
SELECT *
FROM hub.dbo.'+@Table_Name+' AS T2
WHERE '+@whereCondition+')'
SELECT @SQL
--EXEC(@SQL)
SET @whereCondition = NULL
FETCH NEXT FROM cur_Tabel_Info
INTO @ID, @Table_Name
END
Supposing you had noticed and fixed the flaw, your answer sharing is always welcome.
If you have any question, feel free to let me know.
Eric Zhang
TechNet Community Support -
hi,
I am reading chapter 10 of expert oracle database architecture by tom kyte, and I am getting a little confused. It seems to me as if he is saying that an IOT should be built using the PK of that table. What if our table does not have a PK?
thanksOracleGuy777 wrote:
hi,
I am reading chapter 10 of expert oracle database architecture by tom kyte, and I am getting a little confused. It seems to me as if he is saying that an IOT should be built using the PK of that table. What if our table does not have a PK? Then you can not create an IOT. It's a rule. http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/schema.htm#i23877
One of the suggestions is 'try it'. So let us do exactly that - create 2 nearly idetical IOTs - one with and the second without a primary key
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Nov 1 11:07:37 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> CREATE TABLE countries_demo
2 ( country_id CHAR(2)
3 CONSTRAINT country_id_nn_demo NOT NULL
4 , country_name VARCHAR2(40)
5 , currency_name VARCHAR2(25)
6 , currency_symbol VARCHAR2(3)
7 , region VARCHAR2(15)
8 , CONSTRAINT country_c_id_pk_demo
9 PRIMARY KEY (country_id ) )
10 ORGANIZATION INDEX
11 /
Table created.
SQL> edit
Wrote file afiedt.buf
1 CREATE TABLE countries_demo2
2 ( country_id CHAR(2)
3 CONSTRAINT country_id_nn_demo NOT NULL
4 , country_name VARCHAR2(40)
5 , currency_name VARCHAR2(25)
6 , currency_symbol VARCHAR2(3)
7 , region VARCHAR2(15) )
8* ORGANIZATION INDEX
SQL> /
ORGANIZATION INDEX
ERROR at line 8:
ORA-25175: no PRIMARY KEY constraint found
SQL>SO the conclusion is, whether it makes sense to us or not, we can not create a table without defining a primary key.
It makes sense to me, since the IOT is actually stored as a unique index with nulls not allowed - for which a PK is a perfect fit. Note that a PK COULD be defined with multiple columns instead of the traditional single column (and often wrong surrogate key) -
How to make a form using a wizard when the table has no primary key ?
Hi,
I want to make a form to update, delete a table. The table has no primary key. The problem is that the Wizard ask for a primary key.
How to avoid using a primary key ? i mean I don't want to create a primary key if is is possible.
I would like to use the wizard; is it possible ?
Thank you for your kind answers.
ChristianI believe the key is choosing 'Interactive' as opposed to 'Classic' in the implementation and then you can choose 'Existing Trigger' for the primary key source and it should work to use an existing column as your proimary key.
Maybe you are looking for
-
We migrated a server (ldap and file serving) to some new machines, which have new names. We've got all of the login and file sharing functionality working on the new machines, but wherever we have a mount of a share in the Login Items for a user, we
-
Safari not playing .mov files
Been trying to figure out why Safari on my iPhone & iPad won't play .mov files. Especially on yahoo mail.
-
Detected custom lifecycle in the ADF application - struts-config.xml is not migrated!! why?
-
My yahoo music won't open up the player
when clicking on the radio or video station it does not start playing, it had worked once be for now can't get the station too start playing when i click play station
-
Mi id de apple ha sido desactivado
need your help. my id apple se desactivo.