Specifies the domain of acceptable values for a particular column or for any column of a user-defined datatype, and creates access rules.
create [or replace] [{and | or} access]] rule [owner.]rule_name as condition_expression
See Managing User Permissions in the System Administration Guide.
If the specified rule name already exists, it is replaced with the new rule definition, but the name is preserved.
A condition_expression takes one argument, which must be prefixed by the @ sign and refers to the value that is entered via the update or insert command. You can use any name or symbol to represent the value when you write the rule. Enclose character and date constants in quotes, and precede binary constants with “0x”.
You can change the definition of the rule when the rule is replaced. The new rule value overrides the old rule value.
create rule limit as @advance < $1000
create rule pubid_rule as @pub_id in ('1389', '0736', '0877')
create rule picture as @value like '_-%[0-9]'
create rule limit as @advance < $1000 select object_id("limit") ----------- 1017051628
This next command replaces the created rule. The limit is changed using the or replace clause. The object ID of the rule remains the same.
create or replace rule limit as @advance < $2000 select object_id("limit") ----------- 1017051628
create access rule uname_acc_rule as @username = suser_name() select object_id("uname_acc_rule") ----------- 1033051685
Replace uname_acc_rule with an OR access rule:
create or replace or access rule uname_acc_rule as @username = suser_name() select object_id("uname_acc_rule") ----------- 1033051685
To hide the text of a rule, use sp_hidetext.
To rename a rule, use sp_rename.
See also sp_bindrule, sp_help, sp_helptext, sp_hidetext, sp_rename, sp_unbindrule in Reference Manual: Procedures
ANSI SQL – Compliance level: Entry-level compliant.
To create rules using ANSI SQL-compliant syntax, use the check clause of the create table statement.
Any user who impersonates the rule owner through an alias or setuser cannot replace the rule.
The permission checks for create rule differ based on your granular permissions settings.
Setting | Description |
---|---|
Enabled | With granular permissions enabled, you must have the create rule privilege to create a rule. To create a rule for another user, you must have the create any rule privilege. You must be the rule owner to replace the rule. |
Disabled | With granular permissions disabled, you must be the database owner, a user with
sa_role, or have the create rule privilege to
create a rule. To create a rule for another user, you must have
sa_role. You must be the rule owner to replace the rule |
Values in event and extrainfo columns of sysaudits are:
Information | Values |
---|---|
Event | 13 |
Audit option | create |
Command or access audited | create rule |
Information in extrainfo |
|