简体   繁体   中英

Problems checking SQL Broker objects before creating them

Is there any way to check SQL Broker before creating then? I really need to skip in case of existing object:

CREATE MESSAGE TYPE MessageType
AUTHORIZATION dbo
VALIDATION = None;

CREATE CONTRACT MessageContract 
(MessageType SENT BY ANY);

I'd like to try something like "IF EXISTS", but I didn't find the proper systable.

Thanks

You can check for the Message type using

exists(
  select * from sys.service_message_types 
  where [name] = 'MessagetypeName'
);

Likewise you can check for the above message_type_id in sys.service_contracts

I've found a way to do it using sys tables like:

IF NOT EXISTS (select * from sys.service_message_types where name = 'MessageType')
begin
    CREATE MESSAGE TYPE MessageType
    AUTHORIZATION dbo
    VALIDATION = None;
end

thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM