473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to discard rows of a text file which does not satisfies foreign key constraint and continue with the rest

Hi All,

I am loading data to a child table from a text file. the text files
also contains data not referenced by parent key. while loading the data
if one row fails to satisfies the constraint everything is getting
rollback..

plz suggest me something.. which will help me to discard the
unsatisfied rows and continue with the rest..

My Query:
LOAD DATA CONCURRENT INFILE
'/remote/srm172/saranya/SOURCECOV/common_shell/output/data/common_shell_exec.dat'
INTO TABLE CS_COMMON_SHELL_EXEC_REG FIELDS TERMINATED BY '#'
(reg_id,func_address);

Error Msg:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key
constraint fails (`sourcecov/CS_COMMON_SHELL_EXEC_REG`, CONSTRAINT
`CS_COMMON_SHELL_EXEC_REG_ibfk_2` FOREIGN KEY (`func_address`)
REFERENCES `CS_COMMON_SHELL_EXEC` (`func_address`))

Thanks
Devi.

Sep 26 '06 #1
5 4556
kutty wrote:
Hi All,

I am loading data to a child table from a text file. the text files
also contains data not referenced by parent key. while loading the data
if one row fails to satisfies the constraint everything is getting
rollback..

plz suggest me something.. which will help me to discard the
unsatisfied rows and continue with the rest..

My Query:
LOAD DATA CONCURRENT INFILE
'/remote/srm172/saranya/SOURCECOV/common_shell/output/data/common_shell_exec.dat'
INTO TABLE CS_COMMON_SHELL_EXEC_REG FIELDS TERMINATED BY '#'
(reg_id,func_address);

Error Msg:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key
constraint fails (`sourcecov/CS_COMMON_SHELL_EXEC_REG`, CONSTRAINT
`CS_COMMON_SHELL_EXEC_REG_ibfk_2` FOREIGN KEY (`func_address`)
REFERENCES `CS_COMMON_SHELL_EXEC` (`func_address`))

Thanks
Devi.
One approach is to load a temporary table which has no
constraints and then insert from the temporary to the child only
those rows where the foreign key constraint is satisfied.

Advantages are that minimal changes are required to your
existing load program and the insert can be handled with a
simple INSERT INTO child (SELECT * FROM temp WHERE constraints
are met); You may have to play around with the syntax -- I can
never remember if you need that parenthesis and/or an AS before
the SELECT.

HTH
Jerry
Sep 26 '06 #2
Hi Jerry,

Thanx a lot..

but..I am loading a huge volume of data (min 2 GB). Two load operations
might increase the loading time. I dont want that to happen.. is there
any possible way to discard the rows which doent satify the constraint?
Oracle support this. It creates a discard file..

Thanks
Kutty

Jerry Gitomer wrote:
kutty wrote:
Hi All,

I am loading data to a child table from a text file. the text files
also contains data not referenced by parent key. while loading the data
if one row fails to satisfies the constraint everything is getting
rollback..

plz suggest me something.. which will help me to discard the
unsatisfied rows and continue with the rest..

My Query:
LOAD DATA CONCURRENT INFILE
'/remote/srm172/saranya/SOURCECOV/common_shell/output/data/common_shell_exec.dat'
INTO TABLE CS_COMMON_SHELL_EXEC_REG FIELDS TERMINATED BY '#'
(reg_id,func_address);

Error Msg:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key
constraint fails (`sourcecov/CS_COMMON_SHELL_EXEC_REG`, CONSTRAINT
`CS_COMMON_SHELL_EXEC_REG_ibfk_2` FOREIGN KEY (`func_address`)
REFERENCES `CS_COMMON_SHELL_EXEC` (`func_address`))

Thanks
Devi.
One approach is to load a temporary table which has no
constraints and then insert from the temporary to the child only
those rows where the foreign key constraint is satisfied.

Advantages are that minimal changes are required to your
existing load program and the insert can be handled with a
simple INSERT INTO child (SELECT * FROM temp WHERE constraints
are met); You may have to play around with the syntax -- I can
never remember if you need that parenthesis and/or an AS before
the SELECT.

HTH
Jerry
Sep 27 '06 #3
On 27 Sep 2006 05:04:45 -0700, in mailing.database.mysql "kutty"
<sa*****@gmail.com>
<11**********************@b28g2000cwb.googlegroups .comwrote:
>| Hi Jerry,
|
| Thanx a lot..
|
| but..I am loading a huge volume of data (min 2 GB). Two load operations
| might increase the loading time.
It might also decrease the load time!
Loading imported data into a non-index, non constrained table is
pretty quick. Then taking that data and only moving the relevant data
is also pretty quick.

Loading imported data into a temp table has the benefits of:
if the import data is corrupted then it is easy to restart the process
without disturbing your live data.
further manipulation of the data can be carried out prior to transfer
to the live tables.
business rules can be applied to the data prior to going live
once the valid data has been processed you can then see what is left
behind and then make a value judgement if this data can be discarded
or incorporated into the live data.
>| I dont want that to happen.. is there
| any possible way to discard the rows which doent satify the constraint?
| Oracle support this. It creates a discard file..
|
| Thanks
| Kutty
|
| Jerry Gitomer wrote:
| kutty wrote:
| Hi All,
|
| I am loading data to a child table from a text file. the text files
| also contains data not referenced by parent key. while loading the data
| if one row fails to satisfies the constraint everything is getting
| rollback..
|
| plz suggest me something.. which will help me to discard the
| unsatisfied rows and continue with the rest..
|
| My Query:
| LOAD DATA CONCURRENT INFILE
| '/remote/srm172/saranya/SOURCECOV/common_shell/output/data/common_shell_exec.dat'
| INTO TABLE CS_COMMON_SHELL_EXEC_REG FIELDS TERMINATED BY '#'
| (reg_id,func_address);
|
| Error Msg:
| ERROR 1452 (23000): Cannot add or update a child row: a foreign key
| constraint fails (`sourcecov/CS_COMMON_SHELL_EXEC_REG`, CONSTRAINT
| `CS_COMMON_SHELL_EXEC_REG_ibfk_2` FOREIGN KEY (`func_address`)
| REFERENCES `CS_COMMON_SHELL_EXEC` (`func_address`))
|
| Thanks
| Devi.
|
| One approach is to load a temporary table which has no
| constraints and then insert from the temporary to the child only
| those rows where the foreign key constraint is satisfied.
| >
| Advantages are that minimal changes are required to your
| existing load program and the insert can be handled with a
| simple INSERT INTO child (SELECT * FROM temp WHERE constraints
| are met); You may have to play around with the syntax -- I can
| never remember if you need that parenthesis and/or an AS before
| the SELECT.
| >
| HTH
| Jerry
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Sep 27 '06 #4
Hi

Thanks Jerry and Jeff for your valuable suggestion. I will try this
approach.

Thanks
Kutty.

Jeff North wrote:
On 27 Sep 2006 05:04:45 -0700, in mailing.database.mysql "kutty"
<sa*****@gmail.com>
<11**********************@b28g2000cwb.googlegroups .comwrote:
| Hi Jerry,
|
| Thanx a lot..
|
| but..I am loading a huge volume of data (min 2 GB). Two load operations
| might increase the loading time.

It might also decrease the load time!
Loading imported data into a non-index, non constrained table is
pretty quick. Then taking that data and only moving the relevant data
is also pretty quick.

Loading imported data into a temp table has the benefits of:
if the import data is corrupted then it is easy to restart the process
without disturbing your live data.
further manipulation of the data can be carried out prior to transfer
to the live tables.
business rules can be applied to the data prior to going live
once the valid data has been processed you can then see what is left
behind and then make a value judgement if this data can be discarded
or incorporated into the live data.
| I dont want that to happen.. is there
| any possible way to discard the rows which doent satify the constraint?
| Oracle support this. It creates a discard file..
|
| Thanks
| Kutty
|
| Jerry Gitomer wrote:
| kutty wrote:
| Hi All,
|
| I am loading data to a child table from a text file. the text files
| also contains data not referenced by parent key. while loading the data
| if one row fails to satisfies the constraint everything is getting
| rollback..
|
| plz suggest me something.. which will help me to discard the
| unsatisfied rows and continue with the rest..
|
| My Query:
| LOAD DATA CONCURRENT INFILE
| '/remote/srm172/saranya/SOURCECOV/common_shell/output/data/common_shell_exec.dat'
| INTO TABLE CS_COMMON_SHELL_EXEC_REG FIELDS TERMINATED BY '#'
| (reg_id,func_address);
|
| Error Msg:
| ERROR 1452 (23000): Cannot add or update a child row: a foreign key
| constraint fails (`sourcecov/CS_COMMON_SHELL_EXEC_REG`, CONSTRAINT
| `CS_COMMON_SHELL_EXEC_REG_ibfk_2` FOREIGN KEY (`func_address`)
| REFERENCES `CS_COMMON_SHELL_EXEC` (`func_address`))
|
| Thanks
| Devi.
|
| One approach is to load a temporary table which has no
| constraints and then insert from the temporary to the child only
| those rows where the foreign key constraint is satisfied.
| >
| Advantages are that minimal changes are required to your
| existing load program and the insert can be handled with a
| simple INSERT INTO child (SELECT * FROM temp WHERE constraints
| are met); You may have to play around with the syntax -- I can
| never remember if you need that parenthesis and/or an AS before
| the SELECT.
| >
| HTH
| Jerry
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Sep 29 '06 #5
Hi All,

This is not working for me..
This approach is fine for smaller tables.But if i try to insert data
from the temporary table to the child table
Error occurs:
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting
transaction

can any one suggest me a solution?

Thanks
Kutty

kutty wrote:
Hi

Thanks Jerry and Jeff for your valuable suggestion. I will try this
approach.

Thanks
Kutty.

Jeff North wrote:
On 27 Sep 2006 05:04:45 -0700, in mailing.database.mysql "kutty"
<sa*****@gmail.com>
<11**********************@b28g2000cwb.googlegroups .comwrote:
>| Hi Jerry,
>|
>| Thanx a lot..
>|
>| but..I am loading a huge volume of data (min 2 GB). Two load operations
>| might increase the loading time.
It might also decrease the load time!
Loading imported data into a non-index, non constrained table is
pretty quick. Then taking that data and only moving the relevant data
is also pretty quick.

Loading imported data into a temp table has the benefits of:
if the import data is corrupted then it is easy to restart the process
without disturbing your live data.
further manipulation of the data can be carried out prior to transfer
to the live tables.
business rules can be applied to the data prior to going live
once the valid data has been processed you can then see what is left
behind and then make a value judgement if this data can be discarded
or incorporated into the live data.
>| I dont want that to happen.. is there
>| any possible way to discard the rows which doent satify the constraint?
>| Oracle support this. It creates a discard file..
>|
>| Thanks
>| Kutty
>|
>| Jerry Gitomer wrote:
>| kutty wrote:
>| Hi All,
>|
>| I am loading data to a child table from a text file. the text files
>| also contains data not referenced by parent key. while loading the data
>| if one row fails to satisfies the constraint everything is getting
>| rollback..
>|
>| plz suggest me something.. which will help me to discard the
>| unsatisfied rows and continue with the rest..
>|
>| My Query:
>| LOAD DATA CONCURRENT INFILE
>| '/remote/srm172/saranya/SOURCECOV/common_shell/output/data/common_shell_exec.dat'
>| INTO TABLE CS_COMMON_SHELL_EXEC_REG FIELDS TERMINATED BY '#'
>| (reg_id,func_address);
>|
>| Error Msg:
>| ERROR 1452 (23000): Cannot add or update a child row: a foreign key
>| constraint fails (`sourcecov/CS_COMMON_SHELL_EXEC_REG`, CONSTRAINT
>| `CS_COMMON_SHELL_EXEC_REG_ibfk_2` FOREIGN KEY (`func_address`)
>| REFERENCES `CS_COMMON_SHELL_EXEC` (`func_address`))
>|
>| Thanks
>| Devi.
>|
>| One approach is to load a temporary table which has no
>| constraints and then insert from the temporary to the child only
>| those rows where the foreign key constraint is satisfied.
>| >
>| Advantages are that minimal changes are required to your
>| existing load program and the insert can be handled with a
>| simple INSERT INTO child (SELECT * FROM temp WHERE constraints
>| are met); You may have to play around with the syntax -- I can
>| never remember if you need that parenthesis and/or an AS before
>| the SELECT.
>| >
>| HTH
>| Jerry
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Oct 11 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil | last post by:
I am using MySQL 4.1.1-1. When I add a "named" foreign key constraint alter table sb_query_nm_sub_tp add constraint f1sbquerynmsubtp foreign key (query_nm) references sb_query_class...
31
by: Robert Brown | last post by:
Let's say I have a type hierarchy: (just an example) the general entity customer: CREATE TABLE customer(customer_id int, customer_name varchar(250), customer_type int) three specific...
1
by: Justin | last post by:
Hi, In the process of localizing the 'regions' table, we added three new tables. The localized data will be stored in the TokenKeys and TokenValues tables. It would be easier if we did away with...
2
by: adammitchell | last post by:
How can you indicate that a FOREIGN KEY constraint references two columns in two different tables? "SQL Server Books Online" show an example of how to reference two columns in the SAME table:...
2
by: Jeremy Chapman | last post by:
Populating a typed dataset from xml document: I created an xml schema (attached below), generated a typed dataset from it, and then programatically I tried to populate the typed dataset by...
2
by: Christopher Weaver | last post by:
I'm trying to insert a new Row within an existing Table within an existing DataSet using the following: DataRow NewTaskRow = dsTaskActivities.Tables.NewRow();...
6
by: Kevin Chambers | last post by:
Hi all-- In an attempt to commit an Access MDB to a versioning system (subversion), I'm trying to figure out how to convert a jet table's metadata to text, a la SaveAsText. The end goal is to...
7
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround...
6
by: Ivan | last post by:
Hello to all and thanks for answer to my topics. I made one stored procedure that delete one table, but when call/execute the procedure this show SQL0532N A parent row cannot be deleted...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.