I couldn't really tell what was the update statement that caused this
delete/insert , but what I can tell you is the data that existed in the
table when the foreign key constraint was violated
Table when the foreign key was violated
BranchID TrxNumber TrxDate DriverID Vehicle Trailer KilometerReading
GDNCount BoxCollected BoxTotal Confirmed EntryDate EntryUser BUID
NINDCDDC000 26 2/12/06 12:00 AM NULL NULL NULL 0 18 347 347 0
2/12/06 5:04 PM shuhaib
Statements that were running causing foreign key violation
{CALL sp_MSdel_IC_ShipGDN_Master ('NINDCDDC000 ', '000026 ')}
{CALL sp_MSins_IC_ShipGDN_Master ('NINDCDDC000 ', '000026 ',
2006-02-12 00:00:00.000, NULL, NULL, NULL, 0, 18, 347, 347, 0, 2006-02-12
17:04:32.297, 'shuhaib ', ' ')}
Schema
CREATE TABLE [dbo].[IC_ShipGDN_Master](
[BranchID] [char](15) NOT NULL,
[TrxNumber] [char](15) NOT NULL,
[TrxDate] [datetime] NOT NULL,
[DriverID] [char](15) NULL,
[Vehicle] [varchar](15) NULL,
[Trailer] [varchar](15) NULL,
[KilometerReading] [int] NOT NULL CONSTRAINT
[DF__IC_ShipGD__Kilom__4E22BDCE] DEFAULT (0),
[GDNCount] [int] NOT NULL CONSTRAINT [DF__IC_ShipGD__GDNCo__4F16E207]
DEFAULT (0),
[BoxCollected] [int] NOT NULL CONSTRAINT [DF__IC_ShipGD__BoxCo__500B0640]
DEFAULT (0),
[BoxTotal] [int] NOT NULL CONSTRAINT [DF__IC_ShipGD__BoxTo__50FF2A79]
DEFAULT (0),
[Confirmed] [tinyint] NOT NULL CONSTRAINT [DF__IC_ShipGD__Confi__51F34EB2]
DEFAULT (0),
[EntryDate] [datetime] NULL,
[EntryUser] [dbo].[BS_User] NULL,
[BUID] [varchar](15) NULL CONSTRAINT [DF__IC_ShipGDN__BUID__52E772EB]
DEFAULT ([dbo].[ST_FN_GETBU](1)),
CONSTRAINT [PK_IC_ShipGDN_Master] PRIMARY KEY CLUSTERED
(
[BranchID] ASC,
[TrxNumber] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
EXEC sys.sp_bindefault @defname=N'[dbo].[DF_Now]',
@objname=N'[dbo].[IC_ShipGDN_Master].[EntryDate]' , @futureonly='futureonly'
GO
EXEC sys.sp_bindefault @defname=N'[dbo].[DF_System_User]',
@objname=N'[dbo].[IC_ShipGDN_Master].[EntryUser]' , @futureonly='futureonly'
go
ALTER TABLE [dbo].[IC_ShipGDN_Master] WITH CHECK ADD CONSTRAINT
[FK_IC_ShipGDN_Master__AR_SalesMan__DriverID] FOREIGN KEY([DriverID])
REFERENCES [dbo].[AR_Salesmen] ([SalesmanId])
GO
ALTER TABLE [dbo].[IC_ShipGDN_Master] WITH CHECK ADD CONSTRAINT
[FK_IC_ShipGDN_Master__ST_Branches__BranchID] FOREIGN KEY([BranchID])
REFERENCES [dbo].[ST_Branches] ([BranchID])
[quoted text, click to view] "Hilary Cotter" <hilary.cotter@gmail.com> wrote in message
news:OuytHTBMGHA.2012@TK2MSFTNGP14.phx.gbl...
> Can you post the schema of the problem table(s) and also the problem
> update delete statements?
>
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
>
http://www.nwsu.com/0974973602.html >
> Looking for a FAQ on Indexing Services/SQL FTS
>
http://www.indexserverfaq.com >
> "Asser Maany" <asser.maany@microtech.com.eg> wrote in message
> news:O0XjZJBMGHA.3408@TK2MSFTNGP12.phx.gbl...
>> Sorry, missed your last comments, there are no cascaded deletes or
>> updates, and I'm not updating the primary key, that is why I don't really
>> understand why is it converted as a delete and update.
>>
>>
>>
>> "Asser Maany" <asser.maany@microtech.com.eg> wrote in message
>> news:ea%23MjDBMGHA.536@TK2MSFTNGP09.phx.gbl...
>>> Thanks for the fast reply, but my point now is how should I deal with it
>>> to enforce the referential integrity, as I said in my employee example,
>>> the delete that SQL server sends will cause a foreign key violation?
>>>
>>>
>>> Regards
>>> Asser Maany
>>>
>>>
>>> "Hilary Cotter" <hilary.cotter@gmail.com> wrote in message
>>> news:OgTCD3AMGHA.3100@tk2msftngp13.phx.gbl...
>>>> If a table is published for replication and updates occurring on it are
>>>> logged in the tlog as an delete insert pair. The log reader will
>>>> construct an equivalent update statement from this delete insert pair -
>>>> unless an update in place cannot occur (ie you are updating a pk amoung
>>>> other events).
>>>>
>>>> I spoke with someone on the query optimizer team about this and he said
>>>> it was for efficiency in the command construction process (IIRC). I
>>>> didn't really follow much more of what he said. Is it also possible
>>>> that you have cascading updates and deletes and you have not checked
>>>> the enforce constraint for replicatioin option?
>>>>
>>>> --
>>>> Hilary Cotter
>>>> Looking for a SQL Server replication book?
>>>>
http://www.nwsu.com/0974973602.html >>>>
>>>> Looking for a FAQ on Indexing Services/SQL FTS
>>>>
http://www.indexserverfaq.com >>>>
>>>> "Asser Maany" <asser.maany@microtech.com.eg> wrote in message
>>>> news:eV2sAbAMGHA.2628@TK2MSFTNGP15.phx.gbl...
>>>>> Hi There,
>>>>>
>>>>> I was troubleshooting a problem in my transactional replication and
>>>>> notices that SQL Server replicates some of my update statements as
>>>>> Delete/Insert pairs, I was really surprised and couldn't understand
>>>>> why SQL server does that, I found an article in MS support web site
>>>>>
http://support.microsoft.com/kb/238254/EN-US/ that is saying more or
>>>>> less that this might happen in some cases, still not convinced why,
>>>>> but this is a fact of life.
>>>>>
>>>>>
>>>>>
>>>>> Found also another article saying that there is a trace flag that
>>>>> would force SQL server to perform an update as an update (not
>>>>> Delete/Insert pair) (
http://support.microsoft.com/kb/302341/EN-US/)
>>>>> but still not in all cases, again failed to understand why.
>>>>>
>>>>>
>>>>>
>>>>> I'm struggling now to understand why does SQL server do that and also
>>>>> want a solution from my problem since these delete/insert statements
>>>>> are conflicting with my database referential integrity, imagine that
>>>>> I'm updating an employee record that is used in almost all my tables
>>>>> and has got foreign keys every where referencing it and SQL Server is
>>>>> deleting this employee when I perform an update on the publisher!!
>>>>>
>>>>>
>>>>>
>>>>> In the first article they are saying that I should change the logic of
>>>>> my triggers or replication stored procedures to handle this case, but
>>>>> how can I detect that the first delete is followed by an insert for
>>>>> the same record and convert them as an update.
>>>>>
>>>>>
>>>>>
>>>>> If you faced this situation before or you have a solution for this
>>>>> dilemma ,please share your experience with me.
>>>>>
>>>>>
>>>>>
>>>>> Thanks in advance
>>>>>
>>>>> Asser Maany
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>