Monday, February 20, 2012

My own little piece of SQL Wierdness

This has me stumped.
I have a parent and a child table with a constraint on the parent's foreign
key in
the child.
So with this in mind, every once in a while when I am exporting data, I get
an error
that there is a row in the child table with and ID that is not in the parent
table.
One of our programmers is using ADO transactions and beginning it in source
code (not
a proc). Then he adds a row to the parent table, gets the ID in one proc an
d adds a
row to the child table in another proc. Then he commits or aborts when he g
ets back
to code.
Can you think of any reason why the row in the child table is there, but the
row in
the parent isn't there when exporting data?
Thanks.Do you have foreign key constraints on your tables? If so, then it sounds
like a query issue. Otherwise, my guess is the programs arent doing
"something" right?
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"Mike Malter" <mikemalter@.newsgroup.nospam> wrote in message
news:ut9Jr40pFHA.3524@.tk2msftngp13.phx.gbl...
> This has me stumped.
> I have a parent and a child table with a constraint on the parent's
> foreign key in the child.
> So with this in mind, every once in a while when I am exporting data, I
> get an error that there is a row in the child table with and ID that is
> not in the parent table.
> One of our programmers is using ADO transactions and beginning it in
> source code (not a proc). Then he adds a row to the parent table, gets
> the ID in one proc and adds a row to the child table in another proc.
> Then he commits or aborts when he gets back to code.
> Can you think of any reason why the row in the child table is there, but
> the row in the parent isn't there when exporting data?
> Thanks.
>|||The foreign key constraint is not being enforced.
exec sp_helpconstraint N'tableName'
The second result set contains a list of constraints. Check the
status_enabled column for the foreign key constraint in question. If it's
Disabled, then the constraint will not be enforced.
"Mike Malter" <mikemalter@.newsgroup.nospam> wrote in message
news:ut9Jr40pFHA.3524@.tk2msftngp13.phx.gbl...
> This has me stumped.
> I have a parent and a child table with a constraint on the parent's
foreign key in
> the child.
> So with this in mind, every once in a while when I am exporting data, I
get an error
> that there is a row in the child table with and ID that is not in the
parent table.
> One of our programmers is using ADO transactions and beginning it in
source code (not
> a proc). Then he adds a row to the parent table, gets the ID in one proc
and adds a
> row to the child table in another proc. Then he commits or aborts when he
gets back
> to code.
> Can you think of any reason why the row in the child table is there, but
the row in
> the parent isn't there when exporting data?
> Thanks.
>

No comments:

Post a Comment