Foreign keys in source tables (sybase database)
Hi,
Foreign key / primary key constraints are not captured / converted in oracle model nor they are generated.
I am migrating sybase database tables to oracle. These tables have foreign keys, but while capturing and then converting the table to oracle model and then generating, these foreign keys are not present in the ddl script.
In the source connection ( in the tool) to the sybase database, these keys are shown,
and logically when the generation is done for table, the foreign / primary key syntax should be present in the ddl generated
Am more worried about the foreign key not getting converted
Please help
Regards
Hello,
do you have a very simple example showing this behaviour ?
What is your sybase version ? And what about Sqldev version ?
Do you tested migration with offline method ?
As testcase, a emp and dept schema with foreign key should be ideal.
Thanks
Regards,
Marcello
Similar Messages
-
Using FOreign key constraints on tables in database.
I am student and novice in the field of ORACLE and PL/SQL and Database Creation. I had created a database consisting tables and got problem while applying foreign key constraints.
CUST_MSTR
CREATE TABLE "DBA_BANKSYS"."CUST_MSTR"("CUST_NO" VARCHAR2(10),
"FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25), "LNAME" VARCHAR2(25),
"DOB_INC" DATE NOT NULL, "OCCUP" VARCHAR2(25), "PHOTOGRAPH" VARCHAR2(25),
"SIGNATURE" VARCHAR2(25), "PANCOPY" VARCHAR2(1), "FORM60" VARCHAR2(1));
(CUST_NO is PRIMARY KEY, )
-- EMP_MSTR
CREATE TABLE "DBA_BANKSYS"."EMP_MSTR"("EMP_NO" VARCHAR2(10),
"BRANCH_NO" VARCHAR2(10), "FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25),
"LNAME" VARCHAR2(25), "DEPT" VARCHAR2(30), "DESIG" VARCHAR2(30));
(EMP_NO is primary key )
--NOMINEE_MSTR
CREATE TABLE "DBA_BANKSYS"."NOMINEE_MSTR"("NOMINEE_NO" VARCHAR2(10),
"ACCT_FD_NO" VARCHAR2(10), "NAME" VARCHAR2(75), "DOB" DATE,
RELATIONSHIP" VARCHAR2(25));
(NOMINEE_NO is primary key )
--ADDR_DTLS
CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
"CODE_NO" VARCHAR2(10), "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
"ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
"PINCODE" VARCHAR2(6));
( ADDR_NO is primary key )
Problem: I want to apply foreign key constraints on ADDR_DTLS table so that Before inserting value in ADDR_DTLS table it must check, VALUE in ADDR_DTLS.CODE_NO must be PRESENT either in attribute value CUST_MSTR.CODE_NO or EMP_MSTR.CODE_NO or NOMINEE_MSTR.CODE_NO table .
I applied the foreign key constraints using this syntax
CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
"CODE_NO" VARCHAR2(10), "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
"ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
"PINCODE" VARCHAR2(6),
constraints fk_add foreign key CODE_NO references CUST_MSTR. CODE_NO,
constraints fk_add1 foreign key CODE_NO references EMP_MSTR. CODE_NO,
constraints fk_add2 foreign key CODE_NO references NOMINEE_MSTR.CODE_NO);
(foreign key)
ADDR_DTLS.CODE_NO ->CUST_MSTR.CUST_NO
ADDR_DTLS.CODE_NO ->NOMINEE_MSTR.NOMINEE_NO
ADDR_DTLS.CODE_NO ->BRANCH_MSTR.BRANCH_NO
ADDR_DTLS.CODE_NO ->EMP_MSTR.EMP_NO
When I applied foreign key constraints this way, its gives a error called foreign key constraints violation. (I understand that, its searches the attribute value of ADDR_DTLS.CODE_NO in all the three tables must be present then the value will be inserted. But I want, if the value is in any of the three table then its should insert the value or its gives an error.)
Please help me out, though i put the question and i want too know how to apply the forign key in this way. and is there any other option if foreign key implementation is not pssible.If you are on 11g you can use ON DELETE SET NULL:
CREATE TABLE addr_dtls
( addr_no NUMBER(6) CONSTRAINT addr_pk PRIMARY KEY
, addr_cust_no CONSTRAINT addr_cust_fk REFERENCES cust_mstr ON DELETE SET NULL
, addr_emp_no CONSTRAINT addr_emp_fk REFERENCES emp_mstr ON DELETE SET NULL
, addr_nominee_no CONSTRAINT addr_nominee_fk REFERENCES nominee_mstr ON DELETE SET NULL
, addr_type VARCHAR2(1)
, addr1 VARCHAR2(50)
, addr2 VARCHAR2(50)
, city VARCHAR2(25)
, state VARCHAR2(25)
, pincode VARCHAR2(6) );In earlier versions you'll need to code some application logic to do something similar when a parent row is deleted, as otherwise the only options are to delete the dependent rows or raise an error.
btw table names can be up to 30 characters and don't need to end with MSTR or DTLS, so for example CUSTOMERS and ADDRESSES might be more readable than CUST_MSTR and ADDR_DTLS. Also if the Customer/Employee/Nominee PKs are generated from a sequence they should be numeric.
Edited by: William Robertson on Aug 15, 2010 6:47 PM -
Foreign keys to same table / Who columns in User table???
Hi All,
We are designing a database for our client and we are using common columns in all tables like CreatedBy and UpdatedBy which are foreign keys to USER table. My question is can we use these two columns in USER table and have the foreign key constraints to the same tables?
USER table script will look like following..
CREATE TABLE XX_USER
User_ID VARCHAR2(10)
, CreatedBy NUMBER(10)
, UpdatedBy NUMBER(10)
, User_Name VARCHAR2(100) NOT NULL
, Designation VARCHAR2(100) NOT NULL
, CONSTRAINT USER_ISACTIVE_CHECK CHECK (Is_Active in ('Y', 'N'))
, CONSTRAINT USER_KEY PRIMARY KEY (User_ID),
, CONSTRAINT USER_CREATED_BY FOREIGN KEY (CREATED_BY)
REFERENCES XX_USER (USER_ID)
, CONSTRAINT USER_UPDATED_BY FOREIGN KEY (UPDATED_BY)
REFERENCES XX_USER (USER_ID)
);I think what I am doing (the above script) is not correct. Could someone please suggest me how can solve this issue?
Thanks in advance,
Oraebsuser8644385 wrote:
We are designing a database for our client and we are using common columns in all tables like CreatedBy and UpdatedBy which are foreign keys to USER table. My question is can we use these two columns in USER table and have the foreign key constraints to the same tables?You can. After fixing synatx errors:
SQL> CREATE TABLE XX_USER
2 (
3 User_ID VARCHAR2(10)
4 , CreatedBy NUMBER(10)
5 , UpdatedBy NUMBER(10)
6 , User_Name VARCHAR2(100) NOT NULL
7 , Designation VARCHAR2(100) NOT NULL
8 , Is_Active VARCHAR2(1)
9 , CONSTRAINT USER_ISACTIVE_CHECK CHECK (Is_Active in ('Y', 'N'))
10 , CONSTRAINT USER_KEY PRIMARY KEY (User_ID)
11 , CONSTRAINT USER_CREATED_BY FOREIGN KEY (CreatedBy)
12 REFERENCES XX_USER(USER_ID)
13 , CONSTRAINT USER_UPDATED_BY FOREIGN KEY (UpdatedBy)
14 REFERENCES XX_USER(USER_ID)
15 )
16 /
Table created.
SQL> Now USER_ID is a string while CreatedBy/UpdatedBy is a number. Even though it is allowed, it limits USER_ID to numeric strings and causes implicit conversions while validating. So I would change CreatedBy/UpdatedBy data type to VARCHAR2(10).
SY. -
Delete a user from a table whose name is a foreign key in other tables
Dear All;
I am trying to figure out an easy way to do this. I just recently took someone application who utilized 500 tables. I am trying to delete a user from a table called member_table. However, I am having problems doing so because the user name is a foreign key in other tables which has a relationship with this member_table. I really can't naviagte through all 500 different tables and start deleting the user from each table . hence, I would like to figure out a way to delete the user from the member_table without getting the error message
ORA - 02292 "Integrity Constraint (....) violated child record foundUnless you want to find and re-create all of the FK's that point to that field so you can make them ON DELETE CASCADE (note it is the FK not the PK that has that attribute), you will need to either delete that member id from each of the child tables individually or update each one individually to either null or some valid value in member_table before you can delete the id from member_table.
You can find all of the tables, and the corresponding column_name that have an FK relationship to memeber_table with the following:
SELECT c.table_name, col.column_name
FROM user_constraints c, user_cons_columns col
WHERE c.constraint_name = col.constraint_name and
c.r_constraint_name = (SELECT constraint_name
FROM user_constraints
WHERE table_name = 'MEMBER_TABLE' and
constraint_type = 'P') and
c.constraint_type = 'R';If there are a lot of these, you could use something similar to generate the set of delete/update statements that would be needed.
John -
FOREIGN KEY CONSTRAINT 의 MASTER TABLE NAME 의 확인
제품 : ORACLE SERVER
작성날짜 : 1995-11-02
FOREIGN KEY CONSTRAINT 의 MASTER TABLE NAME 의 확인
===================================================
다음은 FOREIGN KEY CONSTRAINT 이름으로 REFERENCE 하는 TABLE
(MASTER TABLE)을 찾는 SQL SCRIPT이다.
col Primary_key_table format a20
col Constraint_name format a20
select a.object_name Primary_Key_table,
c.name Constraint_name
from dba_objects a,
sys.cdef$ b,
sys.con$ c
where c.name = 'EMP_FOREIGN_KEY' -- CONSTRAINT NAME
and b.con# = c.con#
and b.robj# = a.object_id
/The set of constraints as you show it is valid, but will likely result in a lot of violations since both child columns are larger than the parent. The Oracle 2256 error has nothing to do with data validation, nor with the different lengths of the columns. The documentation says
02256, 00000, "number of referencing columns must match referenced columns"
// *Cause: The number of columns in the foreign-key referencing list is not
// equal to the number of columns in the referenced list.
// *Action: Make sure that the referencing columns match the referenced
// columns.Look at the actual statement that the client ran. It will be different than the one you posted. one of the two column lists will have more columns than the other. -
FOREIGN KEY CONSTRAINT의 MASTER TABLE을 REFERENCE하는 TABLE 찾기
제품 : SQL*PLUS
작성날짜 : 2003-12-17
FOREIGN KEY CONSTRAINT의 MASTER TABLE을 REFERENCE하는 TABLE 찾기
================================================================
Master table 이 dept2일 때, 이 테이블을 참조하는 table들을 찾는 SQL
select x.table_name "reference table"
from
(select distinct r_constraint_name,table_name
from all_constraints
where constraint_type='R' ) x, all_constraints a
where a.table_name = 'DEPT2'
and x.r_constraint_name = a.constraint_name; -
Foreign keys at the table partition level
Anyone know how to create and / or disable a foreign key at the table partition level? I am using Oracle 11.1.0.7.0. Any help is greatly appreciated.
Hmmm. I was under the impression that Oracle usually ignores indices on columns with mostly unique and semi-unique values and prefers to do full-table scans instead on the (questionable) theory that it takes almost as much time to find one or more semi-unique entries in an index with a billion unique values as it does to just scan through three billion fields. Though I tend to classify that design choice in the same category as Microsoft's design decision to start swapping ram out to virtual memory on a PC with a gig of ram and 400 megs of unused physical ram on the twisted theory that it's better to make the user wait while it needlessly thrashes the swapfile NOW than to risk being unable to do it later (apparently, a decision that has its roots in the 4-meg win3.1 era and somehow survived all the way to XP).
-
Update primary key thats also a foreign key in another table
Hi Developers,
I need to update the primary key for a record but it's also the foreign key in another table.
Example,
Table 1 Details
Name : Parent_Table
Columns : ID, Name, Age
Primary Key : ID
Table 2 Details
Name : Child_Table
Columns : ID, Parent_ID, Name, Age
Primary Key : ID
Foreign Key : Parent_ID (Primary Key in Parent_Table)
Parent_Table
ID Name Age
1001 Sam 26
1002 George 25
Child_Table
ID Parent_ID Name Age
1010 1001 Sam 26
1020 1002 George 25
Now I want to update ID (1001) in Parent_table as 2001 and also, I want to update Parent_ID (1001) in Child_Table as 2001.
How we will write the java code to update these columns.
Thanks in advance.dcminter wrote:
If you're looking at changing the primary keys in your data then there's probably something wrong with your data structure.Depends how you feel about business primary keys versus surrogates. Personally I prefer the latter so I'm with you in theory. In practice, however, a DB that uses a business PK may well find that it's a legitimate use case to change the key value (but then that's why I like surrogates in the first place!)Primary keys should not have meaning. -
Determine if database view column is foreign key in underlying table
Hi,
I have posted this same question to the General Database Discussions and JDBC forums.
I am using Oracle database 10g (10.1.0.4.0 - 64 bit production) standard edition on Red Hat Enterprise Linux AS release 3, JDK 1.4.2 and the latest Oracle JDBC (thin) driver.
We have a java GUI application that is a front-end for our database. Some of the data entry screens display data from database views. If a column in the view is a foreign key in the underlying table, we want to display a combo-box with the valid values so that the user can choose a correct value.
Is there some way to know whether a column in a view is a foreign key in the view's underlying table?
Thanks,
Avi.I take that back.. I did figure something out for ya.. After reading some elses post I wrote this code... but its time to go home... I believe this will show you all the constraints and constraint types for the underlying tables of all the views for a user. You can mess with it and get it to return only FK (constraint_type = 'R') and only for a single view if ya like... The all_dependencies data dictionary view is the key to this whole operation...
select con.table_name, ucc.column_name, con.constraint_name, con.constraint_type
from all_constraints con, all_cons_columns ucc
where con.owner = user and
con.owner = ucc.owner and
con.table_name = ucc.table_name and
con.table_name in
(SELECT referenced_name
FROM all_dependencies
WHERE referenced_owner = USER
AND referenced_type = 'TABLE'
AND type = 'VIEW'); -
Basic doubt about Primary Key/Foreign Key in Oracle Tables
Hi,
I have a doubt whether Primary Keys/Foreign Keys are allowed in Oracle. Some of the people I know are telling me that Oracle does not encourage having Primary Keys/Foreign keys in its database tables.
However if I go to the ETRM and look for information about some of the Oracle Tables, I am informed that Primary Keys do exist. However I am being told that ETRM is not a reliable way of having correct information about table structure.
It would be great if any one of you provides me with some insight in this. Any pointers to a document would be great.
ThanksIt is not that PK/FKs are disallowed in Oracle Apps (there are some on the standard Oracle Apps tables), but they are typically not used. I am not positive what the logic behind this is, but my guess is that it was party due to the earlier versions of Oracle Apps pre-dating declarative database referential integrity in Oracle DB and also on performance issues with the standard referential integrity with the earlier versions of declarative database referential integrity.
As far as eTRM is concerned - I understood that the data is based on a design repository rather than a physical Oracle Apps DB. So all of the information in there is logically correct, but not necessarily enforced via the standard Oracle DB declarative referential integrity (rather by the application code or APIs). -
Syntax for creating foreign key across users in a database
There are two user present A,B.They are granted all privileges.Now in USER A, there is a table PARENT whose primary key is PARENT_NO.In USER B I have created a table CHILD whose primary key is CHILD_NO.
In the CHILD table of USER B, I want to create a foreign key relation to the PARENT table of USER A.For this I have created a column CHILD_PARENT_NO in the CHILD table.If anybody knows the syntax please post the syntax for creating the required foreign key relationship?Please post your code. Cut'n'paste from SQL*Plus like this...
SQL> conn a/a
Connected.
SQL> desc t1
Name Null? Type
COL1 NUMBER
COL2 VARCHAR2(10)
SQL> grant references on t1 to b;
Grant succeeded.
SQL> conn b/b
SQL> create synonym a_t for a.t1;
Synonym created.
SQL> alter table test add constraint fk foreign key (n) references a_t(col1);
Table altered.
SQL> Note that Oracle will translate the synonym anyway...
SQL> select constraint_name, r_owner, r_constraint_name
2 from user_constraints
3 where table_name = 'TEST'
4 /
CONSTRAINT_NAME R_OWNER R_CONSTRAINT_NAME
FK A T1_PK
SQL> By the way, this ...
GRANT ALL PRIVILEGES TO B;... is a mindbendingly unsafe way of proceeding. In real life you would have given user B the power to utterly destroy your database. It's always easier to start with good habits than to break bad ones so please get used to granting only the minimum set of privileges necessary.
Cheers, APC -
Basic doubt about Primary Keys/Foreign Keys in Oracle Tables
Hi,
I have a doubt whether Primary Keys/Foreign Keys are allowed in Oracle or not. I have been informed that Oracle does not encourage having Primary Keys/Foreign keys in its database tables. Instead it urges users to have unique constraints on the requisite columns.
However if I go to the ETRM and look for information about some of the Oracle Tables, I am informed that Primary Keys do exist. At the same time, I am being told that ETRM is not a reliable way of having correct information about table structure (at least the Primary Key information).
It would be nice if any one of you provides me with some insight in this. Any pointers to a document would be welcome.
ThanksFYI,
There is seprate forum for Core Sql quieries
PL/SQL
Thanks -
Hello,
On a MySQL Database this Table is given:
CREATE TABLE Device (
DeviceID int(11) NOT NULL auto_increment,
TypeID int(11) default NULL,
Type ID is a foreign Key that references to another Table which maps the number to a VARCHAR fpr example
1 --> Printer
2 --> Screen
3 --> Notebook
I want to visualize the MySQL Table in a JTable, but of course I don't want to show the TypeID but the real Name.
On the other hand.... When the user updates the JTable (i.e deletes printer in a cell and types in Notebook) we don't have to store Notebook, but 3 in MySQL Table "Device".
So, do you have a simple and small Solution of how to show the reference of the Foreign key, but to update the foreign Key????Don't cross-post:
http://forum.java.sun.com/thread.jsp?forum=48&thread=463134&tstart=0&trange=15 -
Question on indexing foreign key for replicated table
Hi everybody,
I have 2 tables with following script
create table
parent(parent_id number(2) not null,
parent_name varchar(20),
constraint parent_pk primary key(parent_id))
create table child(child_id number(2) not null,
parent_id number(2) not null,
child_name varchar2(20),
constraint pk_child primary key(child_id,parent_id),
constraint fk_child foreign key (parent_id) references parenr(parent_id)
I want to replicate them and I know to replicate these 2 tables i should add them to my replication group, my question is that the child_id has foreign key so as below link says
http://dbataj.blogspot.com/2007/11/advance-replication-part-ii-master.html
I should put an index on the foreign key.What type of index should it be and is the following script correct for my purpose?
CREATE BITMAP
INDEX "fk_child"
ON child ("PARENT_ID")
TABLESPACE "USERS"
I would appreciate your help in advance.
MeryA bitmap index is almost certainly not the sort of index you'd want to create. You would normally want just a normal index, i.e.
CREATE INDEX fk_child
ON child( parent_id )on the master database just to support normal DML operations (otherwise, deleting a row from the parent table requires doing a full table scan on the child table to see if there are any orphaned child records).
If you are trying to set up a multi-master replication environment, you would also need to replicate this index, since you'll want to support basic DML on both nodes.
Justin -
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
-
Change in delivery quantity for batch managed items.
30.09.2010 Hi friends, We have activated batch management. During delivery after the batch is determined and if i want to change the delivery quantity say for example from 50 to 30 then first i have to go and adjust the quantity in the batches to toa
-
Windows 7 professional - 32 Bit - preloaded - how to go for Win 7 professional - 64 bit option
Hi ! I recently purchased T510 Laptop with pre loaded Win 7 professional 32 bit OS. I want to upgrade this to Win 7 professional 64 bit. I tried to get help through Microsoft site and when I enter the Product Key, it requests me to contact Lenovo. Wh
-
Every time I try to burn a CD, iTunes goes non-responsive and I have to cntrl-alt-delete out of the program. Anyone else have this problem?
-
Can I make an ebook on aperture?
Is it possible to make an ebook or convert an existing photo book in Aperture to an ebook?
-
Hi, One of the major concerns regarding security solutions is the way they interact. ISE specifically, is compatible with most of the SIEMs available today, as stated by Cisco (http://www.cisco.com/en/US/prod/vpndevc/ecosystem.html). In my particular