PL/SQL :: Performance Considerations Of Deferred Foreign Key Constraints
Jan 17, 2013
I've tried to search this out on the forums, but I'm not finding anything useful. Point me to a resource that discusses the performance considerations of deferred foreign key constraints? I'm only interested in foreign keys.
How much of a performance difference does it really make?
Am creating a table based on some integrity constraints, but it's not working.
CREATE TABLE member ( member_id NUMBER(10), last_name VARCHAR2(25) NOT NULL, first_name VARCHAR2(25),
[code],,,
Error:
Error report: SQL Error: ORA-02270: no matching unique or primary key for this column-list 02270. 00000 - "no matching unique or primary key for this column-list" *Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement gives a column-list for which there is no matching unique or primary key constraint in the referenced table. *Action: Find the correct column names using the ALL_CONS_COLUMNScatalog view
I have to create indexes on foreign key columns ,now if composite index is already there with foreign key column then that will work or i will have to create a single column index.
Create table Car (Car_cd VARCHAR2(5), Car_Desc VARCHAR2(50) ); alter table Car add constraint Car_PK primary key (Car_CD); INSERT INTO Car (Car_Cd, Car_Desc) VALUES ('CORLA','COROLLA'); Commit; [code]....
The requirement necessitates a new table to map car to manufacturer. This mapping table may later be expanded to contain other attributes Engine, MPG, etc to hold details specific to a car.But this is in future.
--Not able to create this as Car_cd is already a PK in this table and therefore has Unique Index ALTER TABLE Car_Mapping_Details ADD CONSTRAINT Car_Mapping_Details_fk1 FOREIGN KEY (Car_Cd)REFERENCES Car (Car_Cd); [code]....
But in this case the Car_Mapping_Details.Car_cd is itself is a primary key and therefore has Unique index.Although I was able to create foreign key constraint on Car_mapping_details.car_cd column (which is also Primary Key), I was not able to create Foreign Key Index on this column. It gives me Quote:ORA-01408: such column list already indexed.In other words, not creating foreign index for foreign key column lead to table-level lock? Or will the Unique Index in that primary key column be sufficient to avoid table-level lock?
SQL> insert into egg values(1,2); insert into egg values(1,2) * ERROR at line 1: ORA-02291: integrity constraint (SCOTT.EGGREFCHICKEN) violated - parent key not found
why it is not inserting even after doing initially deferred deferrable. I am using SQL Plus to run Queries.
I want to create a store procedure to copy data from a source tables(which may not have any constraints defined) to a table which has primary key, foreign key and unique key constraints.
Any records which are rejected due to these constraints not being satisfied need to go another table.
Once the initial data load is done, these procedures need to be automated(through cron) to do the future incremental uploads in the same manner.
I did import from 9i to 11gr2 , 1. i create 11gr2 DB , 2.created tablespace with 8kb block, 3 imported 9i dump to 11gr2 DB.
Now iam getting SOME ERRORS: In IMP LOG
1. ORA-29339: tablespace block size 4096 does not match configured block sizes == for all the tablespaces.(But i create TBS with 8kb block before IMPORT)
2. ORA-23327: imported deferred rpc data does not match platform of importing db
We all know about the new feature introduced in Oracle 11g ie. "Deferred Segment Space management" in which there in no segment allocated to table which is empty, which means that only the data is going to be inserted in the table the first segment is going to be allocated.
I created a user assigned a default tablespace to it, created 3 tables, two of them having data and 1 empty table.
When I did export using the export utility, I found that the empty table was not included however the same situation contradicted when I did the export using "EXPDP".
I want to know is the something of tables missing in export happen in RMAN backup of the tablespace which I have assigned to that user.
I have an already populated table that refers to a wrong foreign key in another table. I have table abc that has the column fk_id. this column currently refers to column x_id1 in the table abc while it should refer to column x_id2 in xyz. I am trying to replace the data but I guess I miss something in the logic or the right way of doing it:
commit; insert all into abc values (10,'ab1',1) into abc values (11,'ab2',2) into abc values (12,'ab3',5) into abc values (13,'ab4',7) into abc values (14,'ab5',9) into xyz values (1,1,'d1') into xyz values (2,2,'d2') into xyz values (5,3,'d3') into xyz values (7,4,'d4') into xyz values (9,5,'d5') select * from dual; commit;
--this following select returns 5 rows
select * from abc, xyz where abc.fk_id = xyz.x_id1;
-- the following update only updates 3 rows and sets the other 2 -- to null!
update abc set fk_id = (select x_id2 from xyz where xyz.x_id1 = abc.fk_id); commit;
I'm not really sure why oracle is not finding my Foreing Key, I'm creating an easy set of table for a company and I'm declaring all Primary keys and foreing keys as necessary and this is my
I have a parent table called dept and one child table emp which is referenced on deptno and now both have data . Now i want to truncate the dept table and i have truncated emp table after it when i am trying to truncate dept table then oracle throws a error that is-
"ORA-02266: unique/primary keys in table referenced by enabled foreign keys" ,
but when i tried to delete some records 1 by 1 then these have delete but truncate is not still working. why? if i have 10 millon records.
You should almost always index foreign keys because they are frequently used in joins. In addition, if you intend to delete or update unique or primary keys on the parent table, you should index the foreign keys to improve the locking of child records.what I don't understand are, I should create index on foreign key column in parent table or child table or both ?
Is there any view in oracle which gives the foreign key mapping.
E.g.
Table DEPT has DEPTNO as PK. Table Emp has DEPTNO as FK to DEPT.DEPTNO.
I can get the information for DEPT table from R_CONSTRAINT_NAME column of all_constraints table.My requirement is to get the the which column of Emp table refers to DEPT.DEPTNO column .
Say we have an employee(id_emp) table with a primary key on id_emp. We have also some history tables emp_stuff with columns say (id_emp, dat_event, some_stuff) with primary key id_emp, dat_event.
This means that we have a unique index on (id_emp,dat_event). We also have a foreign key id_emp that references employee(id_emp). When we update id_emp on employee, we still have a lock on emp_stuff. According to this (end of the page) :
Quote:So, in short, with releases prior to Oracle Database 11g Release 1, you will want an index on the foreign key of the child table if you do any of the following:
Update the parent table primary key Delete from the parent table Merge into the parent table
So is id_emp in emp_stuff considered as indexed (through the unique index of the primary key) or do we have to add an explicit index like this CREATE INDEX emp_stuff ON emp_stuff(id_emp) to avoide child table locks?
I am trying to establish PK-FK relationship between 2 tables. Table 1 has VACC_ID as a primary key. Table 2 has VACC_ID and SCH_ID as the primary keys. I am trying to add VACC_ID from Table 2 as a FK to Table 1. This is the code I used
I also tried to add it without writing the query and editing the Table 1. By default, I am getting 2 columns(both VACC_ID) in the local column being referenced to the 2 primary keys(VACC_ID and SCH_ID) of table 2. I also uploaded the screeshot of the error, when I run the query.
In my point of view, deferral FK (DFK) are stronger than non-deferral FK (NDFK). In other words, every NDFK can be moved to DFK. Is there a performance issue ?
Now I want to change the deptno from 10 to 20 and 20 to 10 in dept table . So the ouput will be like
deptno| dname|dseq| 20 | CS | 1 10 | SC | 2
when i am deleting that row I am getting error "ORA-02292: integrity constraint (ROP_FK) violated - child record found".IF i am trying to update i am getting unique key contractin failure.
(Even I cannot update the rest of the column values in dept table as it is also having foreign key dependency) i need to put a sql script in production so that it will interchange.
In my sql developer I have created a table. Created primary keys. Using alter table I have also created the foreign key. Now I need to add one more foreign key to the same table. Do I have to drop the existing foreign key and then create the 2 new foreign keys using the alter table condition or can I retain the existing FK and just use alter table to add another FK.
I am working on a new project in OBIEE. I am asked to do the data modeling in the database using oracle sql developer. I have to create the joins based on the requirements. I have the tables created already. But the primary keys for few tables are not defined for few tables. PK-FK joins are also not done properly.
My questions are (1) If I have to define the primary key for the existing tables can I do that using the alter table command or should I create the table all over again and then define it? (2) If I have to make the changes in the existing PK-FK joins how do i go about doing that?
I have few BDs replicated using Advanced Replication, some tables are read only (Basic Replication) and another ones are Updatable (Advanced Replication).
The infraestucture is Materialized View Replication, my trouble is, I do not know how to should treat the updatable tables that have foreign keys, I read in another FAQs that you should replicate the indexes using the same way to replicate tables (dmbs_repcat.create_master_repobject)
Which is the correct manner to treat the foreign keys with this kind of updatable snapshots,
I have a central entity Address. I have other entities that could have many addresses (Organization, Person for eg). The relation between Organization and Address is one to many and the relation between Person and Address is also one to many.When I modelled it, I ended up having two foreign keys in Address (Organization ID and Person ID).The question that is being raised by the client is "As only one of the foreign key would be populated on each record, the other would be null". The client is not comfortable having nullable foreign keys as they won't be able to maintain integrity. One of the requirement is that No orphan records in Address. By modeling the way above, there are chances for having some orphanned records. I tried to explain that this would be controlled by the program to ensure that no orphan records would be there but their question is that what if someone goes directly and enters a record in Address table without any foreign key value (I dont know who would have an insert/update access on the tables other than the dba's).
I am trying to get some pros and cons on using the nullable foreign keys.