Re: Transactions and foreign keys

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



SQL Server handles explicit transactions differently than Access/Jet.
You need to perform the insert into the parent, retrieve the new PK (I
assume this is an identity column), and then use it to create the
child rows. This is best done in a stored procedure that handles all
of the insert operations in an explicit transaction so that they are
all inserted or all rolled back in case of any error.

--Mary

On Thu, 20 Jul 2006 12:35:02 -0700, ScottW
<ScottW@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi All,

I've seen a similar post regarding this, with no suggestions other than a
third party tool.

What I am using is an OleDbConnection / Transaction, because it has to be
SQL Server and MS Access compatible. The code inserts a record in the parent
table, then loops through a bunch of child tables, inserting the related
records. In SQL Server, it throws an exception, stating it violates the
foreign key, in Access it all works fine.


Do the transactions not support this? It seems odd to me that the
transaction would not know about it's own insertions...

Any help would be great!
.



Relevant Pages

  • Re: Transaction Isolation Level
    ... This means that while I initiate a transaction selecting all new orders it ... My query is executed on a SQL server 2005. ... the isolation level you should use is snapshot isolation. ...
    (comp.databases.ms-sqlserver)
  • Re: Windows Completely Locks Up!! FREEZE
    ... failing to start/run the Distributed Transaction Coordinator. ... Error Specifics: ... The Business Contact Manager SQL Server Startup Service service terminated ... The service did not respond to the start or control request in a timely ...
    (microsoft.public.windowsxp.general)
  • Re: Asynchronous Stored Procedure Never Returns - Help?
    ... If you have the Sql Server 2000 or 2005 docs they are thorough and can be ... for Transaction SQL Reference from the drop-down or select a keyword from ... your query in Query Analyzer or Sql Server Management Studio, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Transaction Abort in a trigger SQL 2008, writing to event log
    ... transaction could still be doomed at some point, ... With the current functionality in SQL Server ... you should roll back the transaction in your error handler. ... global cursor in a stored procedure. ...
    (microsoft.public.sqlserver.programming)
  • Re: Transaction Abort in a trigger SQL 2008, writing to event log
    ... I have done some stack trace type of error catching in Powerbuilder, ... transaction could still be doomed at some point, ... With the current functionality in SQL Server ... you should roll back the transaction in your error handler. ...
    (microsoft.public.sqlserver.programming)