-2

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

André IT
  • 45
  • 7

2 Answers2

1

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

Stu
  • 30,392
  • 6
  • 14
  • 33
0

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

André IT
  • 45
  • 7