Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.

share|improve this question
    
Can you explain exactly what you are using a rule for? –  Aaron Bertrand Aug 30 '12 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 '12 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 '12 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 '12 at 13:47
1  
Is there a reason you want to create a RULE rather than use a CHECK constraint? –  Paul White Dec 1 '12 at 5:02

1 Answer 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

share|improve this answer
    
so the variable is used to hold the values.isn't –  Biju jose Aug 31 '12 at 3:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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