2

The syntax for rules in SQL Server 2005 is given:

CREATE RULE [ schema_name . ] rule_name 
AS condition_expression

Whenever using rule, for example:

CREATE RULE list_rule
AS 
@list IN ('1389', '0736', '0877');

Why are we using a variable like @list in it? It doesn't correspond to the table name or anything. Is that used for storing the values given in the IN statement or anything else?

I just need an explanation for this. I know that rules are now deprecated but I am using SQL Server 2005.

7
  • Can you explain exactly what you are using a rule for? Aug 30, 2012 at 4:16
  • the above given example is cut copy from msdn site .rule is used for enforcing constraints right.I have used a rule for primary key in my table .
    – Biju jose
    Aug 30, 2012 at 4:26
  • Any name or symbol can be used to represent the value when creating the rule, but the first character must be the at sign (@). This line has mentioned in that article also. I think this is an standard way that provided by M-S.
    – JP Chauhan
    Aug 30, 2012 at 5:52
  • 4
    Just an FYI .... RULES have been marked deprecated in SQL 2005 & later. They exists, but you are cautioned against using them in new development work. msdn.microsoft.com/en-us/library/ms188064%28v=sql.90%29.aspx
    – EBarr
    Sep 29, 2012 at 13:47
  • It is beneficial to include a reference to your code if it is not your own, gives credit where credit is due (good or bad code).
    – user507
    Sep 29, 2012 at 15:20

1 Answer 1

1

From MSDN

*condition_expression* includes one variable. The at sign (@) precedes each local variable. The expression refers to the value entered with the UPDATE or INSERT statement. Any name or symbol can be used to represent the value when creating the rule, but the first character must be the at sign (@).

http://msdn.microsoft.com/en-us/library/ms188064.aspx

1
  • so the variable is used to hold the values.isn't
    – Biju jose
    Aug 31, 2012 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.