This trigger needs to check the contact1 table for the deleted accountno. If
it is not found there it will then use the record in contact1del.
This trigger works but I know there is a better way to check for the deleted
accountno in contact1 in the IF statement. Accountno values in Contact1 are
always unique
Thank you in advance for reading this. Any help and\or advise on this
trigger in general is greatly appreciated
CREATE TRIGGER Supp_contact_delete ON Contsupp
FOR DELETE
AS
if (SELECT TOP 1 accountno FROM deleted) in (SELECT accountno from Contact1
)
BEGIN
INSERT INTO Contact1Del
(accountno, rectype, contact, title, contsupref, dear, phone1, ext1, fax,
address1, address2, address3, city, state, zip, country, mergecodes,
lastdate, lasttime, recid, company,key5)
SELECT deleted.accountno, deleted.rectype, deleted.contact, deleted.title,
deleted.contsupref, deleted.dear, deleted.phone , deleted.ext,
deleted.fax, deleted.address1,
deleted.address2, deleted.address3, deleted.city, deleted.state,
deleted.zip, deleted.country, deleted.mergecodes, GETDATE(),
deleted.lasttime, deleted.recid, contact1.company, contact1.key5
FROM deleted
INNER join
contact1
ON contact1.accountno = deleted.accountno
WHERE deleted.rectype='C' AND deleted.accountno > ''
END
ELSE
BEGIN
INSERT INTO Contact1Del
(accountno, rectype, contact, title, contsupref, dear, phone1, ext1, fax,
address1, address2, address3, city, state, zip, country, mergecodes,
lastdate, lasttime, recid, company,key5)
SELECT deleted.accountno, deleted.rectype, deleted.contact, deleted.title,
deleted.contsupref, deleted.dear, deleted.phone , deleted.ext,
deleted.fax, deleted.address1,
deleted.address2, deleted.address3, deleted.city, deleted.state,
deleted.zip, deleted.country, deleted.mergecodes, GETDATE(),
deleted.lasttime, deleted.recid, Contact1del.company, Contact1del.key5
FROM deleted
INNER join
contact1del
ON contact1del.accountno = deleted.accountno
WHERE contact1del.rectype IS NULL and deleted.rectype='C'
ENDJenks,
Try using EXISTS instead.
See:
http://msdn.microsoft.com/library/d...br />
0a2b.asp
HTH
Jerry
"jenks" <jenks@.discussions.microsoft.com> wrote in message
news:1D3AE7DF-B678-461B-B0FF-11F4010DFDD6@.microsoft.com...
> This trigger needs to check the contact1 table for the deleted accountno.
> If
> it is not found there it will then use the record in contact1del.
> This trigger works but I know there is a better way to check for the
> deleted
> accountno in contact1 in the IF statement. Accountno values in Contact1
> are
> always unique
> Thank you in advance for reading this. Any help and\or advise on this
> trigger in general is greatly appreciated
>
> CREATE TRIGGER Supp_contact_delete ON Contsupp
> FOR DELETE
> AS
> if (SELECT TOP 1 accountno FROM deleted) in (SELECT accountno from
> Contact1)
> BEGIN
> INSERT INTO Contact1Del
> (accountno, rectype, contact, title, contsupref, dear, phone1, ext1, fax,
> address1, address2, address3, city, state, zip, country, mergecodes,
> lastdate, lasttime, recid, company,key5)
> SELECT deleted.accountno, deleted.rectype, deleted.contact, deleted.title,
> deleted.contsupref, deleted.dear, deleted.phone , deleted.ext,
> deleted.fax, deleted.address1,
> deleted.address2, deleted.address3, deleted.city, deleted.state,
> deleted.zip, deleted.country, deleted.mergecodes, GETDATE(),
> deleted.lasttime, deleted.recid, contact1.company, contact1.key5
> FROM deleted
> INNER join
> contact1
> ON contact1.accountno = deleted.accountno
> WHERE deleted.rectype='C' AND deleted.accountno > ''
> END
> ELSE
> BEGIN
> INSERT INTO Contact1Del
> (accountno, rectype, contact, title, contsupref, dear, phone1, ext1, fax,
> address1, address2, address3, city, state, zip, country, mergecodes,
> lastdate, lasttime, recid, company,key5)
> SELECT deleted.accountno, deleted.rectype, deleted.contact, deleted.title,
> deleted.contsupref, deleted.dear, deleted.phone , deleted.ext,
> deleted.fax, deleted.address1,
> deleted.address2, deleted.address3, deleted.city, deleted.state,
> deleted.zip, deleted.country, deleted.mergecodes, GETDATE(),
> deleted.lasttime, deleted.recid, Contact1del.company, Contact1del.key5
> FROM deleted
> INNER join
> contact1del
> ON contact1del.accountno = deleted.accountno
> WHERE contact1del.rectype IS NULL and deleted.rectype='C'
> END
>|||jenks wrote:
> This trigger needs to check the contact1 table for the deleted
> accountno. If it is not found there it will then use the record in
> contact1del.
> This trigger works but I know there is a better way to check for the
> deleted accountno in contact1 in the IF statement. Accountno values
> in Contact1 are always unique
> Thank you in advance for reading this. Any help and\or advise on this
> trigger in general is greatly appreciated
>
> CREATE TRIGGER Supp_contact_delete ON Contsupp
> FOR DELETE
> AS
> if (SELECT TOP 1 accountno FROM deleted) in (SELECT accountno from
> Contact1)
> BEGIN
> INSERT INTO Contact1Del
> (accountno, rectype, contact, title, contsupref, dear, phone1, ext1,
> fax, address1, address2, address3, city, state, zip, country,
> mergecodes, lastdate, lasttime, recid, company,key5)
> SELECT deleted.accountno, deleted.rectype, deleted.contact,
> deleted.title, deleted.contsupref, deleted.dear, deleted.phone ,
> deleted.ext,
> deleted.fax, deleted.address1,
> deleted.address2, deleted.address3, deleted.city, deleted.state,
> deleted.zip, deleted.country, deleted.mergecodes, GETDATE(),
> deleted.lasttime, deleted.recid, contact1.company, contact1.key5
> FROM deleted
> INNER join
> contact1
> ON contact1.accountno = deleted.accountno
> WHERE deleted.rectype='C' AND deleted.accountno > ''
> END
> ELSE
> BEGIN
> INSERT INTO Contact1Del
> (accountno, rectype, contact, title, contsupref, dear, phone1, ext1,
> fax, address1, address2, address3, city, state, zip, country,
> mergecodes, lastdate, lasttime, recid, company,key5)
> SELECT deleted.accountno, deleted.rectype, deleted.contact,
> deleted.title, deleted.contsupref, deleted.dear, deleted.phone ,
> deleted.ext,
> deleted.fax, deleted.address1,
> deleted.address2, deleted.address3, deleted.city, deleted.state,
> deleted.zip, deleted.country, deleted.mergecodes, GETDATE(),
> deleted.lasttime, deleted.recid, Contact1del.company, Contact1del.key5
> FROM deleted
> INNER join
> contact1del
> ON contact1del.accountno = deleted.accountno
> WHERE contact1del.rectype IS NULL and deleted.rectype='C'
> END
IF EXISTS (
SELECT *
FROM dbo.Contact1
INNER JOIN deleted
on deleted.accountno = Contact1.accountno )
But your original code does not handle multi-row deletes where one row
deleted exists in the Contact1 table and one row that is deleted does
not. Tthe EXISTS code above won't work correctly in that case either.
You could just always run both inserts for rows that exist and for rows
that do not, assuming those rows are mutually exclusive and forget
checking for existence.
David Gugick
Quest Software
www.imceda.com
www.quest.com|||In this case, the deleted rows with rectype of 'C' will always have an
accountno value in one of the two tables(contact1 or contact1del). EXISTS
will always work, unless I am missing something.
Thanks alot guys. Really appreciate it.
"David Gugick" wrote:
IF EXISTS (
SELECT *
FROM dbo.Contact1
INNER JOIN deleted
on deleted.accountno = Contact1.accountno )
> But your original code does not handle multi-row deletes where one row
> deleted exists in the Contact1 table and one row that is deleted does
> not. Tthe EXISTS code above won't work correctly in that case either.
> You could just always run both inserts for rows that exist and for rows
> that do not, assuming those rows are mutually exclusive and forget
> checking for existence.
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
>|||David, I just read your response more carefully and I see I missed your poin
t.
In this case, the records are touched through a front end app. All Contsupp
records with a rectype of 'C' will always have an associated Accountno in
Contact1. It is possible to delete individual Contsupp records, in which cas
e
the first part of the query with the IF EXISTS statement will be true. The
second part of the trigger is to handle deletion of Contact1 records. When a
Contact1 record is deleted, the associated Contsupp records are automaticall
y
deleted imediately after the Contact1 record. (there is a deletion trigger o
n
Contact1 as well).
Again, thank you for taking a look
"jenks" wrote:
> In this case, the deleted rows with rectype of 'C' will always have an
> accountno value in one of the two tables(contact1 or contact1del). EXISTS
> will always work, unless I am missing something.
> Thanks alot guys. Really appreciate it.
> "David Gugick" wrote:
> IF EXISTS (
> SELECT *
> FROM dbo.Contact1
> INNER JOIN deleted
> on deleted.accountno = Contact1.accountno )
>|||jenks wrote:
> In this case, the deleted rows with rectype of 'C' will always have an
> accountno value in one of the two tables(contact1 or contact1del).
> EXISTS will always work, unless I am missing something.
> Thanks alot guys. Really appreciate it.
> "David Gugick" wrote:
> IF EXISTS (
> SELECT *
> FROM dbo.Contact1
> INNER JOIN deleted
> on deleted.accountno = Contact1.accountno )
Let's say that two rows are deleted in a single statement:
Delete from dbo.Contsupp
Where accountno in (1, 2)
One of the rows deleted exists in Contact1. The other one doesn't. The
EXISTS statement will return true because one row exists in the
relationship between deleted and Contact1 and the corresponding insert
will take place. However, there is another row in the deleted table
which does not exist in Contact1 and its insert will not be executed.
So I think you still have a problem in your code.
David Gugick
Quest Software
www.imceda.com
www.quest.com
Showing posts with label deleted. Show all posts
Showing posts with label deleted. Show all posts
Wednesday, March 28, 2012
Wednesday, March 7, 2012
Monitor show distribution agent that was removed.
While setting up transaction replication from 7 to 2000 I generate a push
subscription that failed to copy the initial schema over. I deleted the
subscription that had caused the problem and started another, that finished
okay and is replicating now. However in the Replication
Monitor-Publishers-servername-publicationname I have the failed agent from
the initial subscription and can not remove it. The same thing applies to
the Replication Monitor-Agents-Distribution Agents. It just won't go away.
SQL7 is the publisher and distributor as well as pushing a subscription to
the SQL2000 box.
Ant help would be appreciated.
Hi Charles,
From your descriptions, I understood that you would like to delete failed
agent but failed to do so. Have I understood you? If there is anything I
misunderstood, please feel free to let me know
Based on my knowledge, when you try to delete them, what's the error
message that shows you are denied to do so? More detailed information will
get us closer to the resolutions.
Secondly, I would like to strongly recommand you the following document,
which show you how to remove a replication manually
How to manually remove a replication in SQL Server 2000
http://support.microsoft.com/?id=324401
Hope this helps, if you have any questions or concerns, don't hesitate to
let me know. We are here to be of assistance!
Sincerely yours,
Mingqing Cheng
Microsoft Online Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only, many thanks!
|||Mingqing,
I can't delete the failed subscription because it does not appear in the
list when I look in the list of subscriptions, the only place that it
appears is in the Monitor. There no way to delete it as far as I know other
than from with in the Publication Properties-Subscriptions and it does not
appear there. The current work subscription is there.
Charlie
""Mingqing Cheng [MSFT]"" <v-mingqc@.online.microsoft.com> wrote in message
news:uLj4km2TEHA.2436@.cpmsftngxa10.phx.gbl...
> Hi Charles,
> From your descriptions, I understood that you would like to delete failed
> agent but failed to do so. Have I understood you? If there is anything I
> misunderstood, please feel free to let me know
> Based on my knowledge, when you try to delete them, what's the error
> message that shows you are denied to do so? More detailed information will
> get us closer to the resolutions.
> Secondly, I would like to strongly recommand you the following document,
> which show you how to remove a replication manually
> How to manually remove a replication in SQL Server 2000
> http://support.microsoft.com/?id=324401
> Hope this helps, if you have any questions or concerns, don't hesitate to
> let me know. We are here to be of assistance!
> Sincerely yours,
> Mingqing Cheng
> Microsoft Online Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
> Please reply to newsgroups only, many thanks!
>
>
|||Hi Charlie,
Thanks for your prompt updates!
Based on my knowledge, the list of Agents being displayed in Replication
Monitor are stored in the Tempdb database in the MSreplication_agent_status
table. You could removing a "left over" agent from this table will delete
it from Replication Monitor listing. You can delete any Agent from this
table without causing problems to Replication.
Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are here to be of assistance!
Sincerely yours,
Mingqing Cheng
Microsoft Developer Community Support
Introduction to Yukon! - http://www.microsoft.com/sql/yukon
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only, many thanks!
|||Mingqing,
Thanks for your reply. But it looks like it cleared it's self up over the
weekend.
Charles Deaton
""Mingqing Cheng [MSFT]"" <v-mingqc@.online.microsoft.com> wrote in message
news:W%2345a5fUEHA.432@.cpmsftngxa10.phx.gbl...
> Hi Charlie,
> Thanks for your prompt updates!
> Based on my knowledge, the list of Agents being displayed in Replication
> Monitor are stored in the Tempdb database in the
MSreplication_agent_status
> table. You could removing a "left over" agent from this table will delete
> it from Replication Monitor listing. You can delete any Agent from this
> table without causing problems to Replication.
> Thank you for your patience and cooperation. If you have any questions or
> concerns, don't hesitate to let me know. We are here to be of assistance!
>
> Sincerely yours,
> Mingqing Cheng
> Microsoft Developer Community Support
> Introduction to Yukon! - http://www.microsoft.com/sql/yukon
> This posting is provided "as is" with no warranties and confers no rights.
> Please reply to newsgroups only, many thanks!
>
subscription that failed to copy the initial schema over. I deleted the
subscription that had caused the problem and started another, that finished
okay and is replicating now. However in the Replication
Monitor-Publishers-servername-publicationname I have the failed agent from
the initial subscription and can not remove it. The same thing applies to
the Replication Monitor-Agents-Distribution Agents. It just won't go away.
SQL7 is the publisher and distributor as well as pushing a subscription to
the SQL2000 box.
Ant help would be appreciated.
Hi Charles,
From your descriptions, I understood that you would like to delete failed
agent but failed to do so. Have I understood you? If there is anything I
misunderstood, please feel free to let me know

Based on my knowledge, when you try to delete them, what's the error
message that shows you are denied to do so? More detailed information will
get us closer to the resolutions.
Secondly, I would like to strongly recommand you the following document,
which show you how to remove a replication manually
How to manually remove a replication in SQL Server 2000
http://support.microsoft.com/?id=324401
Hope this helps, if you have any questions or concerns, don't hesitate to
let me know. We are here to be of assistance!
Sincerely yours,
Mingqing Cheng
Microsoft Online Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only, many thanks!
|||Mingqing,
I can't delete the failed subscription because it does not appear in the
list when I look in the list of subscriptions, the only place that it
appears is in the Monitor. There no way to delete it as far as I know other
than from with in the Publication Properties-Subscriptions and it does not
appear there. The current work subscription is there.
Charlie
""Mingqing Cheng [MSFT]"" <v-mingqc@.online.microsoft.com> wrote in message
news:uLj4km2TEHA.2436@.cpmsftngxa10.phx.gbl...
> Hi Charles,
> From your descriptions, I understood that you would like to delete failed
> agent but failed to do so. Have I understood you? If there is anything I
> misunderstood, please feel free to let me know

> Based on my knowledge, when you try to delete them, what's the error
> message that shows you are denied to do so? More detailed information will
> get us closer to the resolutions.
> Secondly, I would like to strongly recommand you the following document,
> which show you how to remove a replication manually
> How to manually remove a replication in SQL Server 2000
> http://support.microsoft.com/?id=324401
> Hope this helps, if you have any questions or concerns, don't hesitate to
> let me know. We are here to be of assistance!
> Sincerely yours,
> Mingqing Cheng
> Microsoft Online Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
> Please reply to newsgroups only, many thanks!
>
>
|||Hi Charlie,
Thanks for your prompt updates!
Based on my knowledge, the list of Agents being displayed in Replication
Monitor are stored in the Tempdb database in the MSreplication_agent_status
table. You could removing a "left over" agent from this table will delete
it from Replication Monitor listing. You can delete any Agent from this
table without causing problems to Replication.
Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are here to be of assistance!
Sincerely yours,
Mingqing Cheng
Microsoft Developer Community Support
Introduction to Yukon! - http://www.microsoft.com/sql/yukon
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only, many thanks!
|||Mingqing,
Thanks for your reply. But it looks like it cleared it's self up over the
weekend.
Charles Deaton
""Mingqing Cheng [MSFT]"" <v-mingqc@.online.microsoft.com> wrote in message
news:W%2345a5fUEHA.432@.cpmsftngxa10.phx.gbl...
> Hi Charlie,
> Thanks for your prompt updates!
> Based on my knowledge, the list of Agents being displayed in Replication
> Monitor are stored in the Tempdb database in the
MSreplication_agent_status
> table. You could removing a "left over" agent from this table will delete
> it from Replication Monitor listing. You can delete any Agent from this
> table without causing problems to Replication.
> Thank you for your patience and cooperation. If you have any questions or
> concerns, don't hesitate to let me know. We are here to be of assistance!
>
> Sincerely yours,
> Mingqing Cheng
> Microsoft Developer Community Support
> Introduction to Yukon! - http://www.microsoft.com/sql/yukon
> This posting is provided "as is" with no warranties and confers no rights.
> Please reply to newsgroups only, many thanks!
>
Labels:
agent,
copy,
database,
deleted,
distribution,
failed,
generate,
initial,
microsoft,
monitor,
mysql,
oracle,
pushsubscription,
replication,
schema,
server,
setting,
sql,
transaction
Subscribe to:
Posts (Atom)