Home Check if a rule already exists
Reply: 1

Check if a rule already exists

Anil Bakirci
1#
Anil Bakirci Published in 2017-11-13 14:15:19Z

When creating a rule for a user defined data type, how do I check if the rule already exists?

-- does rule exist?
CREATE RULE MyRule
AS @MyVar IN ('foo1', 'foo2')
TheGameiswar
2#
TheGameiswar Reply to 2017-11-13 14:25:08Z
if not  exists(Select 1 from sys.all_objects where type='r')
begin

create rule syntax

end

You could also use sys.objects

 if not  exists(Select 1 from sys.objects where type='r')
    begin

    create rule syntax

    end

References:
https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-all-objects-transact-sql

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.294979 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO