:::: MENU ::::

Bind or Unbind a rule through sp_bind and sp_unbind

  • Mar 19 / 2009
  • 0
Constraints and Keys, dbDigger, T-SQL Scripts

Bind or Unbind a rule through sp_bind and sp_unbind

RULES are SQL Server objects used to implement restrictions and checks on data in a column. A single created RULE may be bind to many columns. Suppose we have a RULE created. This rules specify that minimum DOB of an employee being entered should always be greater than or equal to 18 years. Now once RULE is created then it can be bind to many columns of date of birth in different tables. And all bind columns will accept date of birth greater than or equal to 18 years of age.
To bind a column DOB in Employees table following is syntax

Use Databasename
GO

EXEC sp_bindrule ‘MinDOB’, ‘Employees.DOB’
GO

Similarly same RULE may be bind to as many columns in a database as required. Now in order to drop a RULE, it should be first unbind from all bind columns. So to unbind MinDOB from [Employees].[DOB] following is the syntax

Use Databasename
GO

EXEC sp_unbindrule ‘Employees.DOB’
GO

For details of creating and using rules and defaults in SQL Server please read my article on MSSQLTips.com

Consult us to explore the Databases. Contact us