Using access and extended access rules

Create access rules

The following steps create access rules.

create access rule empid1_access
as @empid = 1

create access rule deptno1_access
as @deptid = 2

The following steps create OR access rules.

create or access rule name1_access
as @name = "smith"
create or access rule phone_access
as @phone = "9999"

Create table

This step creates a test table.

create table testtab1 (empno int, deptno int,name char(10), phone char(4))

Bind rules to table

The following steps bind access rules to the test table columns.

sp_bindrule empid1_access, "testtab1.empno"
/*Rule bound to table column.*/
(return status = 0)sp_bindrule deptno1_access,"testtab1.deptno"
/*Rule bound to table column.*/(return status = 0)sp_bindrule name1_access,"testtab1.name"
/*Rule bound to table column.*/(return status = 0)sp_bindrule phone_access,"testtab1.phone"
/*Rule bound to table column.*/(return status = 0)

Insert data into table

The following steps insert values into the test table.

insert testtab1 values (1,1,"smith","3245")
(1 row affected)insert testtab1 values(2,1,"jones","0283")
(1 row affected)insert testtab1 values(1,2,"smith","8282")(1 row affected)insert testtab1 values(2,2,"smith","9999")(1 row affected)