Foreign Keys b/w two schema
Hi grus
is it possible to make a foreign key on a table in schemaA referenced by a table in SchemaB?
For this you on will go to need the privilege 'references'.
With the <schemaA>:
grant references on <table_schemaA> to <schemaB>
With the <schemaB>:
ALTER TABLE <table_schemaB>
ADD CONSTRAINT <FK_NAME> FOREIGN KEY
("column_schemaB") REFERENCES <schemaA.table_schemaA>
("column_schemaB") ENABLE;
PS.: To substitute the terms that are between < > in accordance with its necessities.
Similar Messages
-
What's the privileges to create foreign key to a different schema.table ?
Hi
In my current schema I want to add a new foreign key. But this key is referencing to a table in a different schema, like this:
Alter table some_table ADD ( Constraint FK_01 Foreign Key (L_ID) References schema.table (LL_ID));
and getting the error - ORA-01031 insufficient privileges
Which privileges do I need for this (At this time, I have only GRANT Select)? Any help would be much appreciated
Best regards
RemoHi,
You need GRANT REFERENCES object privilege to the user.
Cheers -
Multiple foreign key joins between two tables
Hi,
I have a question about building a repository.
I have a date dimension and one fact. The fact table has about 10 foreign key columns that link to the date Dimension.
In this case should I create 10 aliases to create joins in the Physical and BMM layer or is there any other way to handle this situation.
I am asking this question because 10 aliases can get very confusing for me at the later point of time while creating reports.
Using OBIEE 10.1.3Hi
I have a follow up question on this.
I am okay with not seeing the different date tables under the Subject area. Even if it just shows a it as a Simple DATE Dimension I am good with it.
In this case which is the efficient way, creating 10 aliases or creating 10 joins in the physical layer. I just figured out that we can create multiple joins between the same set of two tables but do not know how will that effect the way BI server works.
Please help me in understanding this concept.
thanks
This request id for OBIEE 10.1.3 -
Foreign Key join between two columns in a dimension to one column in Fact
Hi,
I have a requirement to join two columns in a Dimension to the same column in the fact.
My reports contains columns from this dimension and will need to use both the joins to get the correct values. So I am not sure if I create an alias to join the second column, if that will be output incorrect values.
How can we achieve this so that I can still use columns from the dimension and still run both the joins in my SQL eventually.
Dimension
Column 1
Column2
Fact
Column 3
Need to map Column1--->Column 3 and Column2 -----> Column 3
ThanksI put it in Dimension and dimension extension scenario with a fact
The possible scenarios are:
1) Column1--->Column 3 and Column2 -----> Column 3
Both Column1 and Column2 have their own logical tables in BMM
2)
Column1--->Column 3
Column1--->Column2
In this case You have Logical table with 2 different sources Column1 and Column2 using column mapping.
you can go for multiple logical sources in this case, based on column selection tables in the join condition -
EServer Model Diagram and Cross Reference schema -Foreign key
Hi,
I am doing reverser engineering to generate ER diagram from Designer. Version of designer I am using is 10.2.0.2.
While trying to generate SMD (Server model Diagram) from existing database schema, it is failing on generating foreign keys reference to other schema and its table.
Can anybody help me to solve the this problem ?
Viral DaveNote 236266.1
CDS-11305 When Capturing a Foreign Key to a Table in Another Schema.
* symptom: CDS-11306 Warning: Foreign Key <name> not processed because dependent Primary Key <name> not chosen for generation or does not exist in target database
* symptom: Foreign Key to a Table in Another Schema is not Capture Designed
* cause: This functionality is NOT supported by Oracle Designer. See: Bug 885654 FOREIGN KEYS TO DIFFERENT SCHEMA THAN BASE TABLE NOT SUPPORTED
fix:
In release 4.4 (6.5.89) and beyond, this functionality is still not
supported, but the following message is issued for clarification:
CDS-15302 Warning: <schema> clause of the relation referenced by foreign
key constraint ... is unsupported
Sorry....Designer will not capture that.
Michael -
Wrong order foreign key constraints
Hi,
i have problems with non-deferred foreing key constraints:
I have a table "PERSON" and a table "ADRESSE" which has a foreign key
to "PERSON". Both tables have primary keys with two columns.
In the mappings I use application identity. The mappings are generated by
xdoclet.
We cannot use deferred constraint because we have to support following
databases: Oracle, Firebird, MS SQL, DB2.
I tested the mappings with Oracle and Firebird and got this exception
(with SQL Trace):
5602 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (1 errors)>
[15 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?) [params=(int) 1, (String) [email protected], (String)
04941 183742, (int) 12761, (int) 1, (int) 1, (String) 0171 2846751,
(String) Oldenburg, (int) 12760, (String) 26129, (int) 1, (null) null,
(String) Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=0]
5602 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
[0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?) [params=(int) 3, (null) null, (null) null, (int) 12764,
(int) 1, (int) 0, (null) null, (String) Sylt, (int) 12759, (String) 25980,
(int) 0, (null) null, (String) Stephanstra__e 47, (String) 04651 19283]
[reused=1]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
[0 ms] executing prepstmnt 13390902 INSERT INTO VAMP.PERSON (ANREDEID, ID,
KUNDENNR, LOESCHBEMERKUNG, MANDANTID, NAME1, NAME2, PERSONENDATUM,
PERSONENORT, TYP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(null)
null, (int) 12759, (String) 9999452800, (null) null, (int) 1, (String)
Horstmann, (String) Manfred, (Timestamp) 1959-03-10 00:00:00.381, (String)
Flensburg, (int) 1] [reused=0]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
[0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?) [params=(int) 1, (String) [email protected], (String)
04941 183742, (int) 12763, (int) 1, (int) 1, (String) 0171 2846751,
(String) Oldenburg, (int) 12759, (String) 26129, (int) 1, (null) null,
(String) Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=2]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
[0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?) [params=(int) 3, (null) null, (null) null, (int) 12762,
(int) 1, (int) 0, (null) null, (String) Sylt, (int) 12760, (String) 25980,
(int) 0, (null) null, (String) Stephanstra__e 47, (String) 04651 19283]
[reused=3]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
[0 ms] executing prepstmnt 13390902 INSERT INTO VAMP.PERSON (ANREDEID, ID,
KUNDENNR, LOESCHBEMERKUNG, MANDANTID, NAME1, NAME2, PERSONENDATUM,
PERSONENORT, TYP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(null)
null, (int) 12760, (String) 9999452801, (null) null, (int) 1, (String)
Horstmann, (String) Christine, (Timestamp) 1972-03-10 00:00:00.381,
(String) Erfurt, (int) 1] [reused=1]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
[0 ms] executing prepstmnt 11320634 INSERT INTO VAMP.NATPERSON
(ANZAHLKINDER, ARBEITGEBERID, BEITRAGSSATZ, BERUFID, BRANCHEID,
FAMILIENSTAND, FAMSTANDSEIT, FINANZAMTID, GEBIETSFREMDERAWG, GUETERSTAND,
IDBEHOERDE, IDNR, KIRCHENSTEUER, KVID, MANDANTID, PERSONID, PRIVATKV,
STAAT, STEUERBERATERID, STEUERKLASSE, STEUERNR, STEUERTARIF, TITEL) VALUES
[params=(int) 0, (null) null, (double) 0.0, (null) null, (int) 12410,
(int) 2, (Timestamp) 1991-12-12 00:00:00.381, (null) null, (int) 0, (int)
3, (null) null, (null) null, (int) 0, (int) 12576, (int) 1, (int) 12760,
(int) 0, (null) null, (null) null, (int) 0, (null) null, (int) 1, (null)
null] [reused=0]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
[0 ms] executing prepstmnt 11320634 INSERT INTO VAMP.NATPERSON
(ANZAHLKINDER, ARBEITGEBERID, BEITRAGSSATZ, BERUFID, BRANCHEID,
FAMILIENSTAND, FAMSTANDSEIT, FINANZAMTID, GEBIETSFREMDERAWG, GUETERSTAND,
IDBEHOERDE, IDNR, KIRCHENSTEUER, KVID, MANDANTID, PERSONID, PRIVATKV,
STAAT, STEUERBERATERID, STEUERKLASSE, STEUERNR, STEUERTARIF, TITEL) VALUES
[params=(int) 0, (null) null, (double) 0.0, (int) 12362, (int) 12378,
(int) 2, (Timestamp) 1991-12-12 00:00:00.381, (null) null, (int) 0, (int)
3, (null) null, (null) null, (int) 0, (int) 12576, (int) 1, (int) 12759,
(int) 0, (null) null, (null) null, (int) 0, (null) null, (int) 1, (null)
null] [reused=1]
5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
errors)> [16 ms] rollback
5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
errors)> return
5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
errors)> [0 ms] close
com.solarmetric.jdbc.ReportingSQLException: ORA-02291: integrity
constraint (VAMP.ADRESSE_PS) violated - parent key not found
{prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART, EMAIL, FAXNR,
ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ, POSTADRESSE,
POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?) [params=(int) 1, (String) [email protected], (String) 04941
183742, (int) 12761, (int) 1, (int) 1, (String) 0171 2846751, (String)
Oldenburg, (int) 12760, (String) 26129, (int) 1, (null) null, (String)
Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=0]} [code=2291,
state=23000]
at
com.solarmetric.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:124)
at
com.solarmetric.jdbc.LoggingConnectionDecorator.access$600(LoggingConnectionDecorator.java:19)
at
com.solarmetric.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:728)
at
com.solarmetric.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:362)
How can I force it to insert in the table "NATPERSON" first and then in
the table "ADRESSE"?
I use following JDBC-drivers:
Firebird: 1.5.5
Oracle: 9.2.0.1.0
My property file:
<!-- standard properties for all dbms -->
<prop key="kodo.LicenseKey">LICENSE KEY REMOVED</prop>
<prop key="kodo.ConnectionFactoryProperties">MaxCachedStatements=150,
MaxActive=50, MaxIdle=50</prop>
<prop key="kodo.FetchBatchSize">200</prop>
<prop key="kodo.DataCache">true(CacheSize=5000)</prop>
<prop key="kodo.RemoteCommitProvider">sjvm</prop>
<prop key="kodo.jdbc.MappingFactory">metadata</prop>
<prop key="kodo.jdbc.ForeignKeyConstraints">true</prop>
<prop key="kodo.jdbc.SchemaFactory">native</prop>
<prop
key="javax.jdo.PersistenceManagerFactoryClass">kodo.jdbc.runtime.JDBCPersistenceManagerFactory</prop>
<prop key="javax.jdo.option.Optimistic">true</prop>
<!-- oracle connection properties -->
<prop key="kodo.jdbc.DBDictionary">oracle</prop>
<prop
key="javax.jdo.option.ConnectionDriverName">oracle.jdbc.driver.OracleDriver</prop>
<prop key="javax.jdo.option.ConnectionURL">..</prop>
<prop key="javax.jdo.option.ConnectionUserName">..</prop>
<prop key="javax.jdo.option.ConnectionPassword">..</prop>
<prop key="kodo.jdbc.SequenceFactory">native</prop>
<prop key="kodo.jdbc.Schemas">..</prop>
<!-- firebird connection properties
<prop key="kodo.jdbc.DBDictionary">kodo.jdbc.sql.FirebirdDictionary</prop>
<prop
key="javax.jdo.option.ConnectionDriverName">org.firebirdsql.jdbc.FBDriver</prop>
<prop key="javax.jdo.option.ConnectionURL">..</prop>
<prop key="javax.jdo.option.ConnectionUserName">..</prop>
<prop key="javax.jdo.option.ConnectionPassword">..</prop>
<prop key="kodo.jdbc.SequenceFactory">native(TableName=SYSDUAL,
Format="SELECT GEN_ID({0},1) FROM {1}")</prop>
-->
My database schema looks like this:
TABLE PERSON
FIELD MANDANTID (SMALLINT REQUIRED COMMENT (""))
FIELD ID (AUTOINC COMMENT (""))
FIELD TYP (SMALLINT REQUIRED COMMENT (""))
FIELD KUNDENNR (CHAR(15) COMMENT ("Kundennummer"))
PRIMARY KEY
FIELD MANDANTID
FIELD ID
FOREIGN KEY MD
TABLE MANDANT
FIELD MANDANTID
INDEX KDNR
FIELD MANDANTID
FIELD KUNDENNR
UNIQUE
TABLE ADRESSE
FIELD MANDANTID (SMALLINT REQUIRED COMMENT (""))
FIELD ID (AUTOINC COMMENT (""))
FIELD PERSONID (LONGINT REQUIRED COMMENT (""))
PRIMARY KEY
FIELD MANDANTID
FIELD ID
FOREIGN KEY PS
TABLE PERSON
FIELD MANDANTID
FIELD PERSONID
My metadata looks like this:
<class name="PersonDO"
identity-type="application"
objectid-class="com.elaxy.vamp.dom.person.PersonDOId"
persistence-capable-superclass="com.elaxy.vamp.dom.AbstractDO">
<extension vendor-name="kodo"
key="jdbc-class-ind"
value="metadata-value">
</extension>
<extension vendor-name="kodo"
key="jdbc-class-ind/column"
value="TYP">
</extension>
<extension vendor-name="kodo"
key="jdbc-class-ind-value"
value="-1">
</extension>
<extension vendor-name="kodo"
key="jdbc-class-map"
value="base">
</extension>
<extension vendor-name="kodo"
key="jdbc-class-map/table"
value="PERSON">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map"
value="value">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map/column"
value="ID">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map"
value="value">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map/column"
value="MANDANTID">
</extension>
<field name="kundenNr"
persistence-modifier="persistent">
</field>
<field name="adressen"
persistence-modifier="persistent">
<collection
element-type="com.elaxy.vamp.dom.person.AdresseDO">
</collection>
<extension vendor-name="kodo"
key="jdbc-field-map"
value="one-many">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-map/ref-column.MANDANTID"
value="MANDANTID">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-map/ref-column.ID"
value="PERSONID">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-map/table"
value="ADRESSE">
</extension>
</field>
.. fields ..
</class>
<class name="AdresseDO"
identity-type="application"
objectid-class="com.elaxy.vamp.dom.person.AdresseDOId"
persistence-capable-superclass="com.elaxy.vamp.dom.AbstractDO">
<extension vendor-name="kodo"
key="jdbc-class-map"
value="base">
</extension>
<extension vendor-name="kodo"
key="jdbc-class-map/table"
value="ADRESSE">
</extension>
<extension vendor-name="kodo"
key="jdbc-sequence-name"
value="ADRESSE_SEQ">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map"
value="value">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map/column"
value="ID">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map"
value="value">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map/column"
value="MANDANTID">
</extension>
.. fields ..
</class>
Many thanks,
JanMarc
This is a part of the output from the "schemagen" tool:
<schemas>
<schema name="VAMP">
<table name="ADRESSE">
<pk name="ADRESSE_PRIMARY">
<on column="ID"/>
<on column="MANDANTID"/>
</pk>
<column name="ADRESSART" type="decimal" type-name="NUMBER"
size="5"/>
<column name="EMAIL" type="varchar" type-name="VARCHAR2"
size="30"/>
<column name="FAXNR" type="varchar" type-name="VARCHAR2"
size="25"/>
<column name="ID" type="decimal" type-name="NUMBER"
not-null="true" size="10"/>
<column name="LAND" type="decimal" type-name="NUMBER"
size="10"/>
<column name="MANDANTID" type="decimal" type-name="NUMBER"
not-null="true" size="5"/>
<column name="MELDEADRESSE" type="decimal" type-name="NUMBER"
size="1"/>
<column name="MOBILNR" type="varchar" type-name="VARCHAR2"
size="25"/>
<column name="ORT" type="varchar" type-name="VARCHAR2"
size="30"/>
<column name="PERSONID" type="decimal" type-name="NUMBER"
not-null="true" size="10"/>
<column name="PLZ" type="varchar" type-name="VARCHAR2"
size="5"/>
<column name="POSTADRESSE" type="decimal" type-name="NUMBER"
size="1"/>
<column name="POSTFACH" type="varchar" type-name="VARCHAR2"
size="10"/>
<column name="STRASSE" type="varchar" type-name="VARCHAR2"
size="30"/>
<column name="TELEFONNR" type="varchar" type-name="VARCHAR2"
size="25"/>
<fk name="ADRESSE_PS" delete-action="cascade"
to-table="VAMP.PERSON">
<join column="MANDANTID" to-column="MANDANTID"/>
<join column="PERSONID" to-column="ID"/>
</fk>
<index name="ADRESSE_ORT">
<on column="MANDANTID"/>
<on column="ORT"/>
</index>
<index name="ADRESSE_PLZ">
<on column="MANDANTID"/>
<on column="PLZ"/>
</index>
<index name="ADRESSE_PS">
<on column="MANDANTID"/>
<on column="PERSONID"/>
</index>
<index name="ADRESSE_STR">
<on column="MANDANTID"/>
<on column="STRASSE"/>
</index>
</table>
The foreign key "ADRESSE_PS" was identified correctly.
I've taken a look at the class OracleDictionary and it seems that the
object "ForeignKey" considers only one column from the foreign keys -
but I use foreign keys that include two columns ("MANDANTID", "PERSONID").
Is that right or are foreign keys with two columns allowed by the
OracleDictionary?
Marc Prud'hommeaux wrote:
Jan-
That is odd ... Kodo should be identifying the foreign keys and ordering
the statements accordingly. The mappings appear correct to me at first
glance. If you run the "schemagen" tool, does Kodo correctly identify
the foreign key constraints in the database? Can you post the output
from the command so we can take a look?
Jan-Esdert Franken wrote:
Hi,
i have problems with non-deferred foreing key constraints:
I have a table "PERSON" and a table "ADRESSE" which has a foreign key
to "PERSON". Both tables have primary keys with two columns.
In the mappings I use application identity. The mappings are generated by
xdoclet.
We cannot use deferred constraint because we have to support following
databases: Oracle, Firebird, MS SQL, DB2.
I tested the mappings with Oracle and Firebird and got this exception
(with SQL Trace):
5602 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (1 errors)>
[15 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?) [params=(int) 1, (String) [email protected], (String)
04941 183742, (int) 12761, (int) 1, (int) 1, (String) 0171 2846751,
(String) Oldenburg, (int) 12760, (String) 26129, (int) 1, (null) null,
(String) Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=0]
5602 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
[0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?) [params=(int) 3, (null) null, (null) null, (int) 12764,
(int) 1, (int) 0, (null) null, (String) Sylt, (int) 12759, (String) 25980,
(int) 0, (null) null, (String) Stephanstra__e 47, (String) 04651 19283]
[reused=1]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
[0 ms] executing prepstmnt 13390902 INSERT INTO VAMP.PERSON (ANREDEID, ID,
KUNDENNR, LOESCHBEMERKUNG, MANDANTID, NAME1, NAME2, PERSONENDATUM,
PERSONENORT, TYP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(null)
null, (int) 12759, (String) 9999452800, (null) null, (int) 1, (String)
Horstmann, (String) Manfred, (Timestamp) 1959-03-10 00:00:00.381, (String)
Flensburg, (int) 1] [reused=0]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
[0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?) [params=(int) 1, (String) [email protected], (String)
04941 183742, (int) 12763, (int) 1, (int) 1, (String) 0171 2846751,
(String) Oldenburg, (int) 12759, (String) 26129, (int) 1, (null) null,
(String) Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=2]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
[0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?) [params=(int) 3, (null) null, (null) null, (int) 12762,
(int) 1, (int) 0, (null) null, (String) Sylt, (int) 12760, (String) 25980,
(int) 0, (null) null, (String) Stephanstra__e 47, (String) 04651 19283]
[reused=3]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
[0 ms] executing prepstmnt 13390902 INSERT INTO VAMP.PERSON (ANREDEID, ID,
KUNDENNR, LOESCHBEMERKUNG, MANDANTID, NAME1, NAME2, PERSONENDATUM,
PERSONENORT, TYP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(null)
null, (int) 12760, (String) 9999452801, (null) null, (int) 1, (String)
Horstmann, (String) Christine, (Timestamp) 1972-03-10 00:00:00.381,
(String) Erfurt, (int) 1] [reused=1]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
[0 ms] executing prepstmnt 11320634 INSERT INTO VAMP.NATPERSON
(ANZAHLKINDER, ARBEITGEBERID, BEITRAGSSATZ, BERUFID, BRANCHEID,
FAMILIENSTAND, FAMSTANDSEIT, FINANZAMTID, GEBIETSFREMDERAWG, GUETERSTAND,
IDBEHOERDE, IDNR, KIRCHENSTEUER, KVID, MANDANTID, PERSONID, PRIVATKV,
STAAT, STEUERBERATERID, STEUERKLASSE, STEUERNR, STEUERTARIF, TITEL) VALUES
[params=(int) 0, (null) null, (double) 0.0, (null) null, (int) 12410,
(int) 2, (Timestamp) 1991-12-12 00:00:00.381, (null) null, (int) 0, (int)
3, (null) null, (null) null, (int) 0, (int) 12576, (int) 1, (int) 12760,
(int) 0, (null) null, (null) null, (int) 0, (null) null, (int) 1, (null)
null] [reused=0]
5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
[0 ms] executing prepstmnt 11320634 INSERT INTO VAMP.NATPERSON
(ANZAHLKINDER, ARBEITGEBERID, BEITRAGSSATZ, BERUFID, BRANCHEID,
FAMILIENSTAND, FAMSTANDSEIT, FINANZAMTID, GEBIETSFREMDERAWG, GUETERSTAND,
IDBEHOERDE, IDNR, KIRCHENSTEUER, KVID, MANDANTID, PERSONID, PRIVATKV,
STAAT, STEUERBERATERID, STEUERKLASSE, STEUERNR, STEUERTARIF, TITEL) VALUES
[params=(int) 0, (null) null, (double) 0.0, (int) 12362, (int) 12378,
(int) 2, (Timestamp) 1991-12-12 00:00:00.381, (null) null, (int) 0, (int)
3, (null) null, (null) null, (int) 0, (int) 12576, (int) 1, (int) 12759,
(int) 0, (null) null, (null) null, (int) 0, (null) null, (int) 1, (null)
null] [reused=1]
5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
errors)> [16 ms] rollback
5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
errors)> return
5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
errors)> [0 ms] close
com.solarmetric.jdbc.ReportingSQLException: ORA-02291: integrity
constraint (VAMP.ADRESSE_PS) violated - parent key not found
{prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART, EMAIL, FAXNR,
ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ, POSTADRESSE,
POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?) [params=(int) 1, (String) [email protected], (String) 04941
183742, (int) 12761, (int) 1, (int) 1, (String) 0171 2846751, (String)
Oldenburg, (int) 12760, (String) 26129, (int) 1, (null) null, (String)
Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=0]} [code=2291,
state=23000]
at
com.solarmetric.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:124)
at
com.solarmetric.jdbc.LoggingConnectionDecorator.access$600(LoggingConnectionDecorator.java:19)
at
com.solarmetric.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:728)
at
com.solarmetric.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:362)
How can I force it to insert in the table "NATPERSON" first and then in
the table "ADRESSE"?
I use following JDBC-drivers:
Firebird: 1.5.5
Oracle: 9.2.0.1.0
My property file:
<!-- standard properties for all dbms -->
<prop key="kodo.LicenseKey">LICENSE KEY REMOVED</prop>
<prop key="kodo.ConnectionFactoryProperties">MaxCachedStatements=150,
MaxActive=50, MaxIdle=50</prop>
<prop key="kodo.FetchBatchSize">200</prop>
<prop key="kodo.DataCache">true(CacheSize=5000)</prop>
<prop key="kodo.RemoteCommitProvider">sjvm</prop>
<prop key="kodo.jdbc.MappingFactory">metadata</prop>
<prop key="kodo.jdbc.ForeignKeyConstraints">true</prop>
<prop key="kodo.jdbc.SchemaFactory">native</prop>
<prop
key="javax.jdo.PersistenceManagerFactoryClass">kodo.jdbc.runtime.JDBCPersistenceManagerFactory</prop>
<prop key="javax.jdo.option.Optimistic">true</prop>
<!-- oracle connection properties -->
<prop key="kodo.jdbc.DBDictionary">oracle</prop>
<prop
key="javax.jdo.option.ConnectionDriverName">oracle.jdbc.driver.OracleDriver</prop>
<prop key="javax.jdo.option.ConnectionURL">..</prop>
<prop key="javax.jdo.option.ConnectionUserName">..</prop>
<prop key="javax.jdo.option.ConnectionPassword">..</prop>
<prop key="kodo.jdbc.SequenceFactory">native</prop>
<prop key="kodo.jdbc.Schemas">..</prop>
<!-- firebird connection properties
<prop key="kodo.jdbc.DBDictionary">kodo.jdbc.sql.FirebirdDictionary</prop>
<prop
key="javax.jdo.option.ConnectionDriverName">org.firebirdsql.jdbc.FBDriver</prop>
<prop key="javax.jdo.option.ConnectionURL">..</prop>
<prop key="javax.jdo.option.ConnectionUserName">..</prop>
<prop key="javax.jdo.option.ConnectionPassword">..</prop>
<prop key="kodo.jdbc.SequenceFactory">native(TableName=SYSDUAL,
Format="SELECT GEN_ID(,1) FROM ")</prop>
-->
My database schema looks like this:
TABLE PERSON
FIELD MANDANTID (SMALLINT REQUIRED COMMENT (""))
FIELD ID (AUTOINC COMMENT (""))
FIELD TYP (SMALLINT REQUIRED COMMENT (""))
FIELD KUNDENNR (CHAR(15) COMMENT ("Kundennummer"))
PRIMARY KEY
FIELD MANDANTID
FIELD ID
FOREIGN KEY MD
TABLE MANDANT
FIELD MANDANTID
INDEX KDNR
FIELD MANDANTID
FIELD KUNDENNR
UNIQUE
TABLE ADRESSE
FIELD MANDANTID (SMALLINT REQUIRED COMMENT (""))
FIELD ID (AUTOINC COMMENT (""))
FIELD PERSONID (LONGINT REQUIRED COMMENT (""))
PRIMARY KEY
FIELD MANDANTID
FIELD ID
FOREIGN KEY PS
TABLE PERSON
FIELD MANDANTID
FIELD PERSONID
My metadata looks like this:
<class name="PersonDO"
identity-type="application"
objectid-class="com.elaxy.vamp.dom.person.PersonDOId"
persistence-capable-superclass="com.elaxy.vamp.dom.AbstractDO">
<extension vendor-name="kodo"
key="jdbc-class-ind"
value="metadata-value">
</extension>
<extension vendor-name="kodo"
key="jdbc-class-ind/column"
value="TYP">
</extension>
<extension vendor-name="kodo"
key="jdbc-class-ind-value"
value="-1">
</extension>
<extension vendor-name="kodo"
key="jdbc-class-map"
value="base">
</extension>
<extension vendor-name="kodo"
key="jdbc-class-map/table"
value="PERSON">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map"
value="value">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map/column"
value="ID">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map"
value="value">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map/column"
value="MANDANTID">
</extension>
<field name="kundenNr"
persistence-modifier="persistent">
</field>
<field name="adressen"
persistence-modifier="persistent">
<collection
element-type="com.elaxy.vamp.dom.person.AdresseDO">
</collection>
<extension vendor-name="kodo"
key="jdbc-field-map"
value="one-many">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-map/ref-column.MANDANTID"
value="MANDANTID">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-map/ref-column.ID"
value="PERSONID">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-map/table"
value="ADRESSE">
</extension>
</field>
.. fields ..
</class>
<class name="AdresseDO"
identity-type="application"
objectid-class="com.elaxy.vamp.dom.person.AdresseDOId"
persistence-capable-superclass="com.elaxy.vamp.dom.AbstractDO">
<extension vendor-name="kodo"
key="jdbc-class-map"
value="base">
</extension>
<extension vendor-name="kodo"
key="jdbc-class-map/table"
value="ADRESSE">
</extension>
<extension vendor-name="kodo"
key="jdbc-sequence-name"
value="ADRESSE_SEQ">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map"
value="value">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map/column"
value="ID">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId"
value="">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map"
value="value">
</extension>
<extension vendor-name="kodo"
key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map/column"
value="MANDANTID">
</extension>
.. fields ..
</class>
Many thanks,
Jan
Marc Prud'hommeaux
SolarMetric Inc. -
Using one user account table across multiple databases but account used as a foreign key
I want to use one user account table from one database and use it across a couple other databases. The problem is that I want some tables to use the primary key from the user account table as a foreign key to access the data when the user logs in. Is this
the right way of going about it? Do I have to create a user account table in all my databases? What is the best practice to handle this problem? Thanks in advance.You can use Triggers or using replication.
more info:
Add Foreign Key relationship between two Databases
SQL Server Replication
Saeid Hasani [sqldevelop] -
Optional Composite Foreign Key
The tool doesn't seem to be handling this correctly when some of the columns are mandatory and others are nullable. I have a composite foreign key where one column is part of the primary key and the other is not. In the Columns properties of the Table dialog, it shows the column that is part of the primary key as mandatory. But on the diagram, the "red dot" indicator is missing. It also give me an error on the Foreign Keys properties when I click OK or Apply.
No, You cant get a composite keys based on two different primary keys. Reason for this can be like unique index is being used when we create any primary key. When we create a composite primary key, one index is created for the two fields and thus one index store the values for two columns involved in the composite primary key and these values are stored in pairs. So when any foreign key references this composite primary key, it will match the data in pairs as it is stored in the index(unique index).
Now when we say to create a composite foreign key based on two different primary keys , we are taking into account two indexes for two different fields. So there is no pairing in these two indexes. So when we will create foreign key using this, it will not get a pair of values or we can say oracle cant get us consistent pair of values from two indexes. So maintaining integrity will not be possible.
Yes you can create two foreign keys on one column which can refer two different primary keys.
Regards -
Dear All
please correct this syntax for composite foreign key.
Ater Table emp_pays
Add Constraints emp_pt_fk Foreign Key(emp_id,pt_id) Referenes emp(emp_id),pay_type(pt_id);
Thanks in advances
Regards,No, You cant get a composite keys based on two different primary keys. Reason for this can be like unique index is being used when we create any primary key. When we create a composite primary key, one index is created for the two fields and thus one index store the values for two columns involved in the composite primary key and these values are stored in pairs. So when any foreign key references this composite primary key, it will match the data in pairs as it is stored in the index(unique index).
Now when we say to create a composite foreign key based on two different primary keys , we are taking into account two indexes for two different fields. So there is no pairing in these two indexes. So when we will create foreign key using this, it will not get a pair of values or we can say oracle cant get us consistent pair of values from two indexes. So maintaining integrity will not be possible.
Yes you can create two foreign keys on one column which can refer two different primary keys.
Regards -
Foreign key also refer to unique constraint??
foreign key also refer to unique constraint.
(GREAT...)
1.then table that containt unique constraint act as master table??
2.IS unique constraint will replace with primary key??
3.Is unique constraint+not null gives all fuctionality as primary key constraint in ???
4.if primary key=unique+not null then what is use of primary key????????????
thanks
kuljeet pal singhWhen you are establishing a foreign key relationship between two tables, a child record must point to a unique record in the parent table. Typically, the child record points to the primary key of the parent, although any unique field or fields in the parent will do.
So, a table with a unique constraint can act as a parent table in a foreign key relationship.
A unique constraint may be replaced with a primary key, but not neccessarily.
A unique constraint plus a not null constraint is functionally identical to a primary key.
The principle benefit of a primary key compared to unique plus not null is that it provides additional information to someone looking at the database. The primary key is the unchanging identifier for a particular record. A unique constraint plus a not null constraint only implies uniqueness. It is somewhat common for unique values to change over time, as long as they remain unique, but a primary key should never change.
TTFN
John -
Foreign Keys and import of tables (ORA-02297)
How can i get all the foreign keys for a particular schema, basically i'm trying to import tables into a particular schema so i'm trying to disable the constraints, truncate the table , import data and then enable the constraints.
but i'm having error like these when i disable all the constraints in this particular schema
Table altered.
alter table STANDINGS disable constraint P_STANDINGS
ERROR at line 1:
ORA-02297: cannot disable constraint (SCDAT.P_STANDINGS) - dependencies exist
alter table STANDPMTS disable constraint P_STANDPMTS
ERROR at line 1:
ORA-02297: cannot disable constraint (SCDAT.P_STANDPMTS) - dependencies existI use a dynamic SQL-Plus script to generate all the constraints for a schema. I then run this SQL to disable the constraints. Sometimes need to run the script more than once depending on the order the constraints are disabled. Once your scripts runs clean, then you can truncate your tables, import your data, and re-enable constraints.
To re-enable, just use and editor to do REPLACE DISABLE WITH ENABLE....
Here is sample of my dynamic sql. Needs to be run as SYSDBA...
set heading off;
spool c:\disable_constraints.sql;
select 'ALTER TABLE ' || owner || '.' || table_name || ' DISABLE CONSTRAINT ' || constraint_name || ';'
from dba_constraints
where owner = '<owner_name>';
spool off;
Hope that helps.. -
I've attempted to identify a primary and foreign key in these two tables, but I am getting a bunch of errors re duplicate keys and column names needing to be unique. Can someone explain to me what I am doing wrong? I have watched numerous tutorials. Perhaps
the primary and foreign key I have identified don't meet the criteria?
CREATE TABLE StockNames
-- Added Primary key to [stock_symbol]
[stock_symbol] VARCHAR(5) NOT NULL CONSTRAINT PK_stock_symbol PRIMARY KEY,
[stock_name] VARCHAR(150) NOT NULL,
[stock_exchange] VARCHAR(50) NOT NULL,
GO
stock_symbol stock_name stock_exchange
AEA American External Accessories NYSE
ASP All Sports Portal NYSE
AIT Anthony Interest Technology NYSE
ATV American Technology Vehicles NYSE
ACM Anderson Charles and Mitchell NYSE
ACH American Career Helpers NYSE
AVA Alleviate America NYSE
and the second table
CREATE TABLE DailyPricesA (
[stock_symbol] VARCHAR (5) NOT NULL CONSTRAINT FK_stocksymbol REFERENCES [StockNames]([stock_symbol]),
[date] VARCHAR (15) NOT NULL,
[stock_price_open] FLOAT (53) NOT NULL,
[stock_price_high] FLOAT (53) NOT NULL,
[stock_price_low] FLOAT (53) NOT NULL,
[stock_price_close] FLOAT (53) NOT NULL,
[stock_volume] INT NOT NULL,
[stock_price_adj_close] FLOAT (53) NOT NULL,
stock_exchange stock_symbol date stock_price_open stock_price_high stock_price_low stock_price_close stock_volume stock_price_adj_close
NYSE AEA 8/02/2010 4.42 4.42 4.21 4.24 205500 4.24
NYSE AEA 5/02/2010 4.42 4.54 4.22 4.41 194300 4.41
NYSE AEA 4/02/2010 4.55 4.69 4.39 4.42 233800 4.42Hi Stan,
I have removed "stock_exchange" - that removed that error. These are the other errors I am experiencing:Msg
2714, Level 16, State 6, Line 8
There is already an object named 'DailyPricesA' in the database.
Msg 2714, Level 16, State 6, Line 36
There is already an object named 'StockNames' in the database.
Msg 2627, Level 14, State 1, Line 47
Violation of PRIMARY KEY constraint 'PK__StockNam__117C59C768B2BB7F'. Cannot insert duplicate key in object 'dbo.StockNames'. The duplicate key value is (AA).
The statement has been terminated.
Msg 1913, Level 16, State 1, Line 54
The operation failed because an index or statistics with name 'SNIndex' already exists on table 'DailyPricesA'.
And the code:
USE NYSEDatabaseProject
-- Drop the table to clean up database.
--DROP TABLE DailyPricesA
--GO
-- Create the table.
CREATE TABLE DailyPricesA (
[stock_symbol] VARCHAR (5) NOT NULL CONSTRAINT FK_stocksymbol REFERENCES [StockNames]([stock_symbol]),
[date] VARCHAR (15) NOT NULL,
[stock_price_open] FLOAT (53) NOT NULL,
[stock_price_high] FLOAT (53) NOT NULL,
[stock_price_low] FLOAT (53) NOT NULL,
[stock_price_close] FLOAT (53) NOT NULL,
[stock_volume] INT NOT NULL,
[stock_price_adj_close] FLOAT (53) NOT NULL,
-- Add a foreign key.
-- [stock_symbol] VARCHAR (5) NOT NULL CONSTRAINT FK_stocksymbol REFERENCES [StockNames]([stock_symbol]),
BULK INSERT DailyPricesA
from 'C:\Users\fenwky\NYSE_daily_prices_A.csv'
-- firstrow = 2 skips the header row, field terminator =',' deterines the separator, and rowterminator defines where the row ends
with (firstrow = 2, fieldterminator = ',', rowterminator = '\n')
GO
-- Create an index named DPAIndex, for the columns stock_symbol//'DPAIndex' already exists on table 'DailyPricesA'
--CREATE INDEX DPAIndex
--ON DailyPricesA (stock_symbol);
-- Drop the table to clean up database.
-- DROP TABLE StockNames
-- GO
CREATE TABLE StockNames
-- Added Primary key to [stock_symbol]
[stock_symbol] VARCHAR(5) NOT NULL CONSTRAINT PK_stock_symbol PRIMARY KEY,
[stock_name] VARCHAR(150) NOT NULL,
[stock_exchange] VARCHAR(50) NOT NULL,
GO
-- Insert the CSV into the table named Stocknames
BULK INSERT StockNames
from 'C:\Users\fenwky\NYSE_stock_names.csv'
-- firstrow = 2 skips the header row, field terminator =',' deterines the separator, and rowterminator defines where the row ends
with (firstrow = 2, fieldterminator = ',', rowterminator = '\n')
GO
-- Create an index named SNIndex, for the columns stock_symbol and stock_exchange.
CREATE INDEX SNIndex
ON DailyPricesA (stock_symbol);
-- Select all from DailyPricesA
select * from StockNames -
Hi
I have 2 tables as below
Item_Master
- item_id
- item_name
- item_rate
Item_Group (can contain only 2 items in a group)
- group_id
- item_id1
- item_id2
now for a report on item_group i have written the following query but that does not work
select a.group_id, a.item_id1||' - '||b.item_name, a.item_id2||' - '||b.item_name
from item_group a, item_master b
where a.item_id1 = b.item_id and a.item_id1 = b.item_id
i dont understand whats the problem
ThanksIf you have two foreign keys, you need two joins:
select a.group_id, a.item_id1||' - '||b1.item_name, a.item_id2||' - '||b2.item_name
from item_group a, item_master b1, item_master b2
where a.item_id1 = b1.item_id
and a.item_id2 = b2.item_id -
Foreign Keys involving two different databases/schemas
Hi -- I'm wondering if it's possible to set a foreign key that involves tables that live in different databases/schemas. And, if it is possible, is it a horrible design idea?
Thanks,
~Christinecav0227, you have asked two different two part questions.
1 - Is it possible to set up FK that span owners and is this good design?
Yes, it is possilbe and there if the data is related then yes it is good design. We like to minimize the number of object owners in our system and use a table naming standard where the first two or three letters of the table name represent a system code: ap, ar, gl for accounts receivable, accounts payable, and general ledger. Other may prefer to have an AP owner, AR owner, and a GL owner.
Ownership has no direct bearing on quality of design. If the tables are related then you should define the FK no matter who the owner is.
2 - Is it possible to define FK to remote (distributed) tables and is the good design? The answer is no. FK cannot reference remote objects. To enforce referencial integrity accross databases via the database, rather than in the application, requires the use of table triggers.
As far as good design that depends on why the data is remote and why the tables need to be linked. There are issues related to availability, recovery, and performance when data is distributed. Having such a relationship could be good design or bad design depending on if all the inter-related factors have been considered.
IMHO -- Mark D Powell -- -
How to create a foreign key for the table from two different tables?
Hi All,
I have a three table like below. In the below table SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK will be having the primary key for NAME column. The same SAMPLE_CONS3_CHECK table also having the primary key for NAME column and forieign key for SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK tables. See the below code 2
code 1:
CREATE TABLE SAMPLE_CONS_CHECK
(NAME VARCHAR2(10),
SERIES VARCHAR2(5)
CREATE TABLE SAMPLE_CONS2_CHECK
(NAME VARCHAR2(5),
MODEL NUMBER
CREATE TABLE SAMPLE_CONS3_CHECK
(NAME VARCHAR2(5),
MODEL_NO NUMBER
)code 2
alter table SAMPLE_CONS_CHECK
add constraint SAMPLE_CONS_CHECK_pk primary key (NAME)
alter table SAMPLE_CONS2_CHECK
add constraint SAMPLE_CONS2_CHECK_pk primary key (NAME)
alter table SAMPLE_CONS3_CHECK
add constraint SAMPLE_CONS3_CHECK_pk primary key (NAME)
ALTER TABLE SAMPLE_CONS3_CHECK ADD
CONSTRAINT SAMPLE_CONS3_CHECK_FK1 FOREIGN KEY
NAME
) REFERENCES SAMPLE_CONS_CHECK
NAME
) ON DELETE CASCADE;
ALTER TABLE SAMPLE_CONS3_CHECK ADD
CONSTRAINT SAMPLE_CONS3_CHECK_FK2 FOREIGN KEY
NAME
) REFERENCES SAMPLE_CONS2_CHECK
NAME
) ON DELETE CASCADE;From the above schenario i am able to insert the data to SAMPLE_CONS3_CHECK table. But the parent data is already available in the parent table. The problem is here two different constarints from two different tables. While inserting, it is checking from both the tables whether the parent is exist or not.
How can i solve this problem? Can anyone halp me about this?
Thanks
Edited by: orasuriya on Aug 8, 2009 2:02 AMActually the design is completely incorrect.
What you say is
I have
'foo', 'foo series'
'foo','foo model'
'foo',666
By virtue of table3 referring to both table1 and table2.
This means you actually need to have 1 (one) table:
'foo','foo series','foo model', 666
And the 'problem' disappears.
Sybrand Bakker
Senior Oracle DBA
Maybe you are looking for
-
Also will the apps that I have not bought with my money from App Store but just downloaded, can I still upgrade them? And what about if I have some music and apps which were not brought from my iPhone 5c which I am currently using, but from my old i
-
How to recover photos after restoring iPod touch?
Yesterday, there was an update for the iOS 6, I believe. When I pressed the update button, a message popped up saying that there was a problem with my iPod touch 4G and that I need to restore it. I had absolutely no idea why that message would pop up
-
Update XML files with a PHP form...
Hi, I would like to know if its possible to update or insert data to XML files from a PHP form? And how can I do it? Basically i want to create a backoffice for my XML Flash slide show. Can anyone help me?
-
Whenever I click on the "Text" icon it locks up my photoshop and my computer
-
Satellite A210-14S - Why do I get Bluescreen error often?
I own a Toshiba A210-14S for about 3 weeks, and got 6 bluescreens by now! Two times, it happend as I transfered data from an external HDD to the Notebook's HDD. One time after installing ICQ from my external HDD. And three other times, it appeared wi