Inserting data into specific columns  Using the NULL character string

Chapter 7: Adding, Changing, and Deleting Data

Restricting column data: rules

You can create a rule and bind it to a column or user-defined datatype. Rules govern the kind of data that can or cannot be added.

The pub_id column of the publishers table is an example. A rule called pub_idrule, which specifies acceptable publisher identification numbers, is bound to the column. The acceptable IDs are “1389,” “0736,” “0877,” “1622,” and “1756,” or any four-digit number beginning with “99.” If you enter any other number, you see an error message.

When you get this kind of error message, you may want to use sp_helptext to look at the definition of the rule: :

sp_helptext pub_idrule 
---------
        1  
 
(1 row affected) 
 
text 
---------------------------------------------------
create rule pub_idrule 
as @pub_id in ("1389", "0736", "0877", "1622", "1756")
or @pub_id like "99[0-9][0-9]" 
 
(1 row affected)

For more general information on a specific rule, use sp_help. Or use sp_help with a table name as a parameter to find out if any of the columns has a rule. See Chapter 13, “Defining Defaults and Rules for Data.”





Copyright © 2005. Sybase Inc. All rights reserved. Using the NULL character string

View this book as PDF