Share via


Lesson 3: Dropping the Conversation Objects

New: 15 September 2007

In this lesson, you will learn to drop the objects that enabled a database to support a conversation in the database.

Procedures

Switch to the AdventureWorks database

  1. Copy and paste the following code into a Query Editor window. Then, run it to switch context to the AdventureWorks database.

    USE AdventureWorks;
    GO
    

Drop the conversation objects

  1. Copy and paste the following code into a Query Editor window. Then, run it to drop the objects that were used to support the conversation.

    IF EXISTS (SELECT * FROM sys.services
               WHERE name =
               N'//AWDB/1DBSample/TargetService')
         DROP SERVICE
         [//AWDB/1DBSample/TargetService];
    
    IF EXISTS (SELECT * FROM sys.service_queues
               WHERE name = N'TargetQueue1DB')
         DROP QUEUE TargetQueue1DB;
    
    -- Drop the intitator queue and service if they already exist.
    IF EXISTS (SELECT * FROM sys.services
               WHERE name =
               N'//AWDB/1DBSample/InitiatorService')
         DROP SERVICE
         [//AWDB/1DBSample/InitiatorService];
    
    IF EXISTS (SELECT * FROM sys.service_queues
               WHERE name = N'InitiatorQueue1DB')
         DROP QUEUE InitiatorQueue1DB;
    
    IF EXISTS (SELECT * FROM sys.service_contracts
               WHERE name =
               N'//AWDB/1DBSample/SampleContract')
         DROP CONTRACT
         [//AWDB/1DBSample/SampleContract];
    
    IF EXISTS (SELECT * FROM sys.service_message_types
               WHERE name =
               N'//AWDB/1DBSample/RequestMessage')
         DROP MESSAGE TYPE
         [//AWDB/1DBSample/RequestMessage];
    
    IF EXISTS (SELECT * FROM sys.service_message_types
               WHERE name =
               N'//AWDB/1DBSample/ReplyMessage')
         DROP MESSAGE TYPE
         [//AWDB/1DBSample/ReplyMessage];
    GO
    

Next Steps

This concludes the tutorial. Tutorials are brief overviews and do not describe all available options. Tutorials have simplified logic and error handling to better focus on fundamental operations. To create efficient, reliable, and robust conversations, you need more complex code than the example in this tutorial.

Return To The Service Broker Tutorials

Service Broker Tutorials

See Also

Other Resources

DROP SERVICE (Transact-SQL)
DROP QUEUE (Transact-SQL)
DROP MESSAGE TYPE (Transact-SQL)
DROP CONTRACT (Transact-SQL)

Help and Information

Getting SQL Server 2005 Assistance