Add the foreign key refers to a different schema
Hello
We have a database with schemaA and schemaB and we use a data model for schemaA with SQL Data Modeler.
Our data model is based on SchemaA and we do not want add schemaB or create subview in our current model for schemaB since our dev team do not want schemaB in the model
We have created a synonym in tableB schemaB shcemaA after granting select them, references to schemaA
We have added a foreign key on tableA in referencing TableB on schemaB schemaA.
for example. Add ALTER table tableA foreign constraint key(column-name) references tableB(colum-name)
So far so good.
But if we try to produce the DDL for tableA it has not provided the ALTAR of the foreign key that is based on shcmeaB
We know that we cannot add foreign key on dblinks.
How can I get the Modeler DDL from SQL data for tableA, including the foreign key
We appreciate the answers
Kind regards
Zafar
Hi zak,.
We have created a synonym in tableB schemaB shcemaA after granting select them, references to schemaA
We have added a foreign key on tableA in referencing TableB on schemaB schemaA.
You can do it in the database because TableB exists in the database and DB knows its definition, including the existing constraint of PK/UK.
This is the same model of data Modeler - you must have the definition of the table referenced in order to create the FK that refer to the constraint of PK/UK.
As it works now (we can change it) you can have modeled for SchemaA and ModelB for SchemaB. Then, you can drag & drop tableB form the Navigator to the diagram of the ModelA and TableB there will exist as an object remote read-only, you can use to create the FK.
With the help of subviews, DDL generation and configurations of reports, you can display the dev team than objects that they want to see - on the charts in generated DDL and reports.
Philippe
Tags: Database
Similar Questions
-
Create a foreign key constraint against a different schema
Hi all
I use the oracle 10g r2 on windows 2003 server database.
I have a table in the HRMS as STAFF.
I have another INVENTORY schema, where I want to access a column as a foreign key in HRMS. STAFF (STAFF_ID).
What exactly I have to grant so this diagram of the INVENTORY will be able to create a referential constraint?connect hrms/hrms@orcl grant select on STAFF to INVENTORY; connect inventory/inventory@orcl alter table inv_details add constraint fk_inv_hr_staff foreign key (staff_id) references HRMS.STAFF(STAFF_ID); Error report: SQL Error: ORA-00942: table or view does not exist 00942. 00000 - "table or view does not exist"
Kind regards.You must also grant the privilege of REFERENCES.
See privileges in table 18-2 at http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_9013.htm#BGBCIIEG
Hemant K Collette
-
How do I change or add constr. foreign key to the table whose children or data lines
Hello
I have a table with the name of Department in which the DEPTNO column is a column of data and primary key in it for all columns. Now, I have a table EMP where DEPTNO column is not having any constraints, including constraint foreign key also. I now have data in the EMP table for all columns. I would now add the DEPTNO column foreign key constraint in the EMP table that references the column DEPTNO in DEPT table. Both the table have not all null values.
I need to add the foreign key without removing the data in the EMP table.
Please advice.
Kind regards
AlriqIn addition, if you have pre-existing data that will never have a parent record but you want to ensure that any NEW data is consistent with the FK constraint you can always create it with the NOVALIDATE option:
SQL> CREATE TABLE EMP_BKP AS SELECT * FROM SCOTT.EMP; Table created. SQL> CREATE TABLE DEPT_BKP AS SELECT * FROM SCOTT.DEPT; Table created. SQL> DELETE FROM DEPT_BKP WHERE DEPTNO=10; 1 row deleted. SQL> ALTER TABLE DEPT_BKP ADD CONSTRAINT DEPT_BKP_PK PRIMARY KEY(DEPTNO); Table altered. SQL> ALTER TABLE EMP_BKP ADD CONSTRAINT DEPT_FK FOREIGN KEY(DEPTNO) REFERENCES DEPT_BKP(DEPTNO); ALTER TABLE EMP_BKP ADD CONSTRAINT DEPT_FK FOREIGN KEY(DEPTNO) REFERENCES DEPT_BKP(DEPTNO) * ERROR at line 1: ORA-02298: cannot validate (TEST_USER.DEPT_FK) - parent keys not found SQL> ALTER TABLE EMP_BKP ADD CONSTRAINT DEPT_FK FOREIGN KEY(DEPTNO) REFERENCES DEPT_BKP(DEPTNO) NOVALIDATE; Table altered. SQL> INSERT INTO EMP_BKP(EMPNO,ENAME,DEPTNO) VALUES(9999,'Test Emp',10); INSERT INTO EMP_BKP(EMPNO,ENAME,DEPTNO) VALUES(9999,'Test Emp',10) * ERROR at line 1: ORA-02291: integrity constraint (TEST_USER.DEPT_FK) violated - parent key not found SQL> SELECT * FROM EMP_BKP WHERE DEPTNO = 10 ORDER BY EMPNO; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- ------------------- ---------- ---------- ---------- 7782 CLARK MANAGER 7839 06/09/1981 00:00:00 2450 10 7839 KING PRESIDENT 11/17/1981 00:00:00 5000 10 7934 MILLER CLERK 7782 01/23/1982 00:00:00 1300 10
-
Index and foreign key referring to itself
Hello!
I'm working on an application that uses a basket stored in a database. The shopping cart uses two tables:
BASKET: Contains the common information for a shopping cart: the user is logged in etc.
-Primary key: CART_ID
CART_ROW: A line in the shopping cart, for example a new product to buy.
-Primary key: ROW_ID
-Foreign key: CART_ROW. References CART_ID CART. CART_ID
On the code lines in the basket are taken by cart, as is modeled by the foreign key. There is a relationship, that we use in the code, but which is not modelled by a foreign key in the database. A line can be dependent on another line, which makes the other row a parent.
CART_ROW has a PARENT_ID column that refers to CART_ROW. ROW_ID.
Would you add a foreign key to PARENT_ID? Or are there issues to consider when it is a foreign key to the same table?
Some time ago, we added the index, both ROW_ID PARENT_ID. The index on PARENT_ID could have harmful, since there is no foreign key?
Best regards!user9005175 wrote:
Hello!I'm working on an application that uses a basket stored in a database. The shopping cart uses two tables:
BASKET: Contains the common information for a shopping cart: the user is logged in etc.
-Primary key: CART_IDCART_ROW: A line in the shopping cart, for example a new product to buy.
-Primary key: ROW_ID
-Foreign key: CART_ROW. References CART_ID CART. CART_IDOn the code lines in the basket are taken by cart, as is modeled by the foreign key. There is a relationship, that we use in the code, but which is not modelled by a foreign key in the database. A line can be dependent on another line, which makes the other row a parent.
CART_ROW has a PARENT_ID column that refers to CART_ROW. ROW_ID.
Would you add a foreign key to PARENT_ID? Or are there issues to consider when it is a foreign key to the same table?I suggest to add the foreign key, it will not harm performance (except during an insert when there is validation of the foreign key). But it would avoid users to insert bad data / corrupted by code or directly on loggin in the database.
Some time ago, we added the index, both ROW_ID PARENT_ID. The index on PARENT_ID could have harmful, since there is no foreign key?
Index on parent_id would be dangerous if you do not use index after it is created (i.e. There is no application that can make use of this index).
And if you decide to have a foreign key parent_id then I suggest to have too many indexes on parent_id because it would be at least useful when you delete a record in this table.Best regards!
-
Schema import Gets the foreign key number
Hi all;
Scott has a table named rank-> he has primary key-> different tablespace
Sharma has a table named emp-> he has foreign key-> different tablespace
$ imp/System Manager queue = refresh_sharma.dmp log = refresh_sharma_imp.log fromuser = touser = sharma sharma
Import: Free 11.2.0.1.0 - Production Thursday, may 7, 18:35:03-2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT: V11.02.00 direct
import in US7ASCII and AL16UTF16 NCHAR character set
import server uses WE8MSWIN1252 (possible character set conversion) character set
Customer export uses the (possible character set conversion) WE8MSWIN1252 character set
. import of objects in SHARMA SHARMA
. . import of partition "CONT_EMP": "P1" 4000 imported lines
. . import of partition "CONT_EMP": "P2" 5000 imported lines
. . import of partition 'CONT_EMP': 'P3' 5000 imported lines
. . "DEPT" table import 12 lines imported
. . import of table 'EMP' 68278 imported lines
. . importing table "EMP_AUDIT" 4 imported lines
. . table 'Method' import 68000 lines imported
. . importing table "EMP_PERS_INFO" 68278 imported lines
. . importing table "EMP_PROJ_INFO" 68278 imported lines
. . table 'LOGTAB' import 603 lines imported
. . table import "PAYROLL" 186282 imported lines
. . import of table 'of the PROJECT"22 rows imported
. . importation of "TAB1" 4000000 imported table rows
. . table import 'TRANSPORT' 0 rows imported
IMP-00017: statement failed with error ORACLE 1031:
'ALTER TABLE 'EMP' ADD 'EMP_EMPLEV_C12_FK' OF CONSTRAINT FOREIGN KEY ("EMP_LEVE" '.
""L") REFERS TO"SCOTT" CATEGORY"("GRADE_NAME") ENABLE NOVALIDATE.
IMP-00003: ORACLE error 1031
ORA-01031: insufficient privileges
About to activate the constraints...
IMP-00017: statement failed with error ORACLE 2430:
' ALTER TABLE 'EMP' ENABLE CONSTRAINT "EMP_EMPLEV_C12_FK"
Import completed successfully with warnings.
30, 31 line number is display error.
'ALTER TABLE 'EMP' ADD 'EMP_EMPLEV_C12_FK' OF CONSTRAINT FOREIGN KEY ("EMP_LEVE" '.
""L") REFERS TO"SCOTT" CATEGORY"("GRADE_NAME") ENABLE NOVALIDATE.
After the import operation, to recreate the foreign key is the right option. but
By performing the import operation, how can all I avoid this error dump file or log file?
I don't want to use constraints = N.
Thanks in advance
You gave * of * SCOTT * at * SHARMA. The grant received by SHARMA not getting exported when you export SHARMA. So, it is not imported when you import SHARMA. If you did an export and import of SCOTT before SHARMA, the award of the cross-schema would have also been imported. (Subsidies granted by a user are exported with the user, the subsidies received by a user are not exported with the user).
Hemant K Collette
-
Renaming of the foreign keys in the relational model
Hello
I'm new to the Data Modeler, we use v 3.0.0.66.5 and Oracle 11 g, and I am trying to build a logic and a relational model for a new application.
We always call our primary keys as the ID, this causes me a problem with my names of foreign keys in the relational model, as they show as ID #. Is it possible to add the abbreviated of the table of the foreign key?
Thanks in advance
SueYes it is.
Take a look at the tools > preferences, select Data Modeler > naming Standard > model, you can specify the standard you want to use for your foreign key. You can apply this designation to existing models and all new created FK uses the same model. To apply the standard to existing templates, select the relational model in the browser, right-click to display the context menu and select the menu "apply Naming standards... ».
Sue
-
Please, I have the following question on the foreign key and the ora-00904
Thanks in advance!
I created the table:
Create the Department table
(
DNAME varchar (15) NOT NULL,
deptID number (5) NOT NULL,
Primary key (dname, deptid)
)
then...
Create table Manager
(
MgrID number (10) not null,
Not null, name varchar (10)
Start_date date not null,
Primary key (mgrid),
CONSTRAINT fk_department
FOREIGN KEY (dname, deptip)
Department of REFERENCES (dname, deptid)
)
Trying to create the table with the constraint, it yeilds one:
ORA-00904: "DNAME": invalid identifier
+.. .with an asterisk under "dname" in line: FOREIGN KEY (dname, deptip) +.
I tried joining my name of the column with quotation marks ("" "); capitalized for consistency; and we tried creating and editing then - all to nothing will do. I also tried to use the user interface with Oracle Express Edition and the moment where I click on create, the same error appears. Could someone help please straighten out me up - was this threat for four days.
Thanks again!Hello
Welcome to the forum!
Columns that will reference the other table must be declared just like all the other columns; including the names in a FOREIGN KEY constraint is not auotmatically define them.
It works:CREATE TABLE Manager ( mgrid NUMBER (10) NOT NULL, Name VARCHAR (10) NOT NULL, Start_date DATE NOT NULL, dname VARCHAR2 (15), -- New deptid NUMBER (5), -- New PRIMARY KEY (mgrid), -- CONSTRAINT fk_department FOREIGN KEY (dname, deptid) REFERENCES department (dname, deptid) );
(assuming that the departments table, you posted, there).
Is there a reason why you use VARCHAR instead of VARCHAR2?
In the departments table, do you really need both dname and deptid in the primary key? For example, if you have a line with name = "ACCOUNTING" and deptid = 10; is it possible that you could have another line with deptid = 10 and some different dname, say 'REASEARCH '? It is more common to only have a deptid as primary key and have columns in the foreign key constraints that reference.
-
How did the foreign key that is recognized by the primary key
Hi, when I have two user tables and userLevel and the primary key of the user is the user name and I add a field to userLevel userID is only to make the userID field in userLevel automatically the foreign key of the table? Or do you switch the engine of MyISAM tables to InnoDB to make relational links. Can someone please explain this in English clear to me, because I just can't get my head around this.
In the case of a query such as SELECT statement, we talked, being a key actually means that the field is indexed so that the database can quickly look up. Thus, in phpMyAdmin, you set the field to be indexed by the visualization of the structure of the table and clicking the icon index (the one with the Lightning) for the field in the Action section.
If you are looking for integrity refrential between tables we also talked about and using the InnoDB engine, you can click the link 'Show the relational' in the table structure page of phpMyAdmin and define foreign key constraints.
-
SQL statement error INSERT The conflicted with the FOREIGN KEY constraint
I recently installed a reporting for vmware vsphere software, but I get a SQL error. I opened a request for assistance with vmware, but so far they have not come up with a solution. The error is caused by: com.microsoft.sqlserver.jdbc.SQLServerException: instruction INSERT The conflicted with the FOREIGN KEY constraint 'FK_CB_VSM_NETWORK_VC_ID '. The conflict occurred in database 'VCChargebackVCC02', table "dbo." " CB_VSM_SERVER', column 'VC_ID '. I don't know a lot about SQL, so I'm lost in the extent of troubleshooting is concerned. If anyone has any ideas I'd love to hear them.
SQL questions are better posed on Technet. They are better equipped to manage the
http://social.technet.Microsoft.com/forums/en-us/categories/
-
Forgive my question. I am very new to Oracle.
How can I make sure that changes in the key primary supplier_id (concerning the supplier table) would also appear directly in the FOREIGN KEY (supplier_id) in the products table?
Is that not all the primary key and FOREIGN KEY on?
My paintings:
I created 2 tables and connect to apply in the data base referential integrity, as I learned.
CREATE TABLE - parent provider
(the numeric (10) of supplier_id not null,)
supplier_name varchar2 (50) not null,
Contact_Name varchar2 (50).
CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
);
CREATE TABLE - child products
(the numeric (10) of product_id not null,)
supplier_id numeric (10) not null,
CONSTRAINT fk_supplier
FOREIGN KEY (supplier_id)
REFERENCES beg (supplier_id)
);
I inserted the following text:
INSERT INTO provider
(supplier_id, supplier_name, contact_name)
VALUES
(5000, 'Apple', 'first name');
I expect that the supplier_id (5000) to the provider of the table also appears in the products table under key supplier_id having the same value which is 5000. But this does not happen.
How to get there?
Thanks in advance!
Hello
What is a foreign key in Oracle?
A foreign key is a way to ensure referential integrity in your Oracle database. A foreign key means that the values of a table must appear also in another table.
Ok!??
What is now the right way to implement referential integrity in your Oracle database that the values of a table must also be included in another table?
A foreign key referential integrity indeed enfore in ensuring that the value in the child table must have a corresponding parent key (otherwise you will encounter an error, as evidenced by "SomeoneElse"). However, it will never automatically insert a row in the other table.
If you are looking for a solution that automatically inserts a record in the other table, maybe you should go for triggers:
See:
-
Term plurals changes the name of the foreign key in the relational model
Hello
I use a glossary with plurals for entities such as Budget turned to the budgets of the table in the relational model. Unfortunately (for me) it also changes the name of the foreign key. In the related entity, an attribute (for example) is Budget_fiscal year, I expect in the relational model, being the same, but it is transformed into budgets_fiscal_year (budgets in the plural rather than keep him in singular form).
How can I avoid any change in the attribute names (in the process of engineering in the relational model) but always turn the names of entities from the singular to the plural names for tables?
Thank you and best regards
Robert
Hi Philippe
Your suggestion 1) works - thank you! budgets_fiscal_year is the attribute of pk exercise in my budget of the entity. It seems a standard behavior of the Data Modeler to compose the UID of the relationship of budgets_fiscal_year (for some reason, this column is not taken the logical model, but the relational model). I would prefer that it be appointed budget_fiscal_year.
I have not defined any parameter for this (intentionally). But maybe somewhere there by default. Could you tell me where the design parameters in Data Modeler to learn how to configure the definitions mentioned in 2)?
As I'm always busy with the model of reverse engineering data, I'll wait for DM 4.1.1.888.
Best regards
Robert
-
Optimize the foreign key for the removal of the cascade constraint.
Hello
JDeveloper version: 11.1.2.3.0
I saw this blog and found something new to me: http://snag.gy/qI6dY.jpg
Jdeveloper user interface, there is an option to select all tables to select the foreign key and set it for the removal of the waterfall.
My project is deployed on multiple databases. I wonder where this change is registered. None of the project files is modified.
Can I make this change (from limitations to the waterfall) for each database that I use?
Here is the blog where I saw that: http://tompeez.wordpress.com/2013/04/22/master-detail-insertdelete-sample/
I have my object associations optimized for the removal of the waterfall, but without the option above together, I always get constraint violations...
Concerning
Not sure however if you set the option the DOF looks like
"EMP_JOB_FK' FOREIGN KEY ('JOB_ID') CONSTRAINT REFERENCES 'HR '. "" SELECT JOBS "("JOB_ID') WE DELETE CASCADE If you set the option to cascade for fk Job_id from the employees table.
Timo
-
Drop partition without disabling the foreign key
Hi all
I have a table parent and child.
Parent table
create the table parent_1
(identification number,
create_date date,
Constraint parent_1_pk001 PRIMARY KEY (id))
PARTITION OF RANGE (create_date)
INTERVAL (NUMTODSINTERVAL(1,'DAY'))
(PARTITION parent_1_part VALUES LESS THAN (January 1, 2010 '));
Child table
create the table child_1
(identification number,
create_date date,
Constraint child_1_fk001 FOREIGN KEY (id)
REFERENCES parent_1 (id))
PARTITION OF RANGE (create_date)
INTERVAL (NUMTODSINTERVAL(1,'DAY'))
(PARTITION create_date_part VALUES LESS THAN (January 1, 2010 '));
I have problems to delete partition.
Parent_1
1 JULY 26, 12
2 JULY 26, 12
Child_1
1 JULY 26, 12
ALTER drop partition table CHILD_1 SYS_P274;
table altered CHILD_1.
ON THE PARENT PARTITION A FALL
ALTER drop partition table parent_1 SYS_P273;
Error report:
SQL error: ORA-02266: unique/primary keys in table referenced by foreign keys enabled
02266 00000 - "unique/primary keys in table referenced by foreign keys enabled.
* Cause: An attempt was made to truncate a single table or
primary keys referenced by foreign keys in another table.
Other unauthorized trades are a drop/truncate partition a
partitioned table or an ALTER TABLE EXCHANGE PARTITION.
* Action: Before performing the operations described above, the table, disable the
constraints foreign key in other tables. You can see what
constraints are making reference to a table by issuing the following
command:
SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'tabnam ';
PLEASE KNOW IF THERE IS A WAY TO THE PARENT PARTITION DROP WITHOUT TOGGLE FOREIGN CONSTRAINTS
Thank youSQL Error: ORA-02266: unique/primary keys in table referenced by enabled foreign keys 02266. 00000 - "unique/primary keys in table referenced by enabled foreign keys" *Cause: An attempt was made to truncate a table with unique or primary keys referenced by foreign keys enabled in another table. Other operations not allowed are dropping/truncating a partition of a partitioned table or an ALTER TABLE EXCHANGE PARTITION. *Action: Before performing the above operations the table, disable the foreign key constraints in other tables.
You can do until you disable the foreign key constraint
http://jonathanlewis.WordPress.com/2006/12/10/drop-parent-partition/
Hope this helps
Mohamed Houri
www.hourim.WordPress.com -
Rename the foreign key constraint
Hello
I have table tbl_a with a column a_col1 SEO tbl_b.b_col1
I want to create the name of the foreign key as FK_A_COL1 constraint which is FK_ < COLUMN NAME OF the CHILD >.
Foreign naming key standards does not have the use of the name of the child under the name column.
Is there any other solution/script to achieve this?
Thank you.fkeys = model.getFKIndexAssociationSet().toArray(); for (var i = 0; i
;//also can use fk.getTable().getAbbreviation()fkname = "FK_"+fk.getTable().getName();cols = fk.getColumns();for( var k = 0;k -
Identify the foreign key table
I have a table that has a few constraints that are foreign keys to other tables (see column FK_ETHNIC below). My naming conventions are consistent so they all start with 'FK_ ". In SQL, how can I find the table that the foreign key column references? I have a process that must find this table and then get all of its columns.
Thank you!
CREATE TABLE STU_BASE
(PK_ID VARCHAR2 (32), sys_guid() by default)
CONSTRAINT pk_stu_base
KEY ELEMENTARY SCHOOL
With the HELP of INDEX TABLESPACE sis_express_index
STORAGE (INITIAL 524288
NEXT 524288
PCTINCREASE 0),.
STUDENT_ID VARCHAR2 (15).
Fk_stu_base_ethnic FK_ETHNIC VARCHAR2 (32) CONSTRAINT
REFERENCES
Ethnic (PK_ID)
REMOVE THE NULL VALUE;
CREATE TABLE ETHNIC
(PK_ID VARCHAR2 (32), sys_guid() by default)
CONSTRAINT pk_ethnic
KEY ELEMENTARY SCHOOL
With the HELP of INDEX TABLESPACE sis_express_index
STORAGE (4096 INITIAL
NEXT 4096
PCTINCREASE 0),.
VARCHAR2 (2) ETHNIC,.
ETHNIC_DESC VARCHAR2 (30),
STATE_CODE VARCHAR2 (2),
FEDERAL_CODE VARCHAR2 (2))You could do a self-join with CONSTRAINTS (USER, ALL, s/n) views. You can search a constrainttype of 'R' and you can attach it to itself based on the R_OWNER and R_CONSTRAINT_NAME columns.
For example:
SELECT r1.owner AS child_owner , r1.table_name AS child_table , r2.owner AS parent_owner , r2.table_name AS parent_table FROM all_constraints r1 JOIN all_constraints r2 ON r2.owner = r1.r_owner AND r2.constraint_name = r1.r_constraint_name WHERE r1.constraint_type = 'R' ;
Published by: Centinul on February 16, 2012 15:36
Maybe you are looking for
-
Loads of bad images on Web pages
I have some questions related to the weird development with images bad load on a web page to place another image. I'm building a logon screen and have a number of images on the page. When I come to the page on Mac book all right, but when I use an
-
C4385 all in a carriage Jam, with paper
I have a HP C4385 all in one and it is a transport and Paper Jam message display, or none at all. Any time I try to print something, I receive one of the above messages. I tried to clean the rollers who drop out paper (via the instructions in a vid
-
Commit complete, although the current recovery log file online have been removed.
Even though I have deleted current online redo log file in the linux operating system (Linux of Oracle), when I hit 'commit' he says it committed "complete." It's just for this princip? *: "if only when all redo records associated with a given transa
-
Update query to a site of muse with regard
Please excuse the fundamental nature of the request, but I'm pretty new to this and this is the first time that this issue has developed. I have a live Webcam site muse hosted on BC that needs to be overhauled. My client does not want all the time an
-
HelloI use the database of 11.2 g XE and PLSQLdeveloper 8. I create a test in plsqldeveloper window and add this code DeclareI have integer;BeginFor i In (Select / * + FIRST_ROWS (5) * /)t.CodCities t) LoopDbms_Output.put_line (I.COD);End loop; End;