Home > OS >  Problems checking SQL Broker objects before creating them
Problems checking SQL Broker objects before creating them

Time:06-17

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

CodePudding user response:

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

CodePudding user response:

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

  • Related