rule 和 check 的区别?

xlhl 2003-05-22 01:31:48
rule 和 check 的区别?
...全文
303 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xlhl 2003-05-22
  • 打赏
  • 举报
回复
明白!谢谢
ldcr520 2003-05-22
  • 打赏
  • 举报
回复
大力概括的精确.
pengdali 2003-05-22
  • 打赏
  • 举报
回复
规则可以邦定到多列
check只能邦定一个表

用规则可以优化你的设计
liukanghui 2003-05-22
  • 打赏
  • 举报
回复
Check Object
The Check object represents the attributes of a single Microsoft® SQL Server™ 2000 integrity constraint.


PropertiesChecked Property Name Property
ExcludeReplication Property Text Property


MethodsRemove Method (Objects) Script Method


Remarks
A SQL Server integrity constraint can be defined as part of a CREATE TABLE statement or can be added to, or removed from, a table as part of an ALTER TABLE statement.

With the Check object, you can:

Define a new integrity constraint for a SQL Server table.


Remove an existing constraint from a SQL Server table.


Generate a Transact-SQL script to document an existing integrity constraint.
The Name property represents a constraint name. It is character data and must be unique within a SQL Server database.

To create a SQL Server integrity constraint

Create a Check object.


Set the Name property.


Set the Text property to define the constraint.
Adding the Check object to its containing collection generates the appropriate CREATE statement. Specify only the integrity test condition in the Text property.

Set the ExcludeReplication property.


Add the Check object to the Checks collection of a Table object.
To remove a SQL Server integrity constraint

Get the appropriate Table object from the Tables collection of a Database object.


Use the BeginAlter method of the Table object to mark the start of alterations on the SQL Server table.


Get the desired Check object from the Checks collection of the Table object.


Use the Remove method of the Check object to drop its integrity constraint from the SQL Server table.


Use the DoAlter method of the Table object to submit the change to the SQL Server.

See Also
-------------------------------
-------------------------------
-------------------------------
Rule Object
The Rule object exposes the attributes of a single Microsoft® SQL Server™ data-integrity rule.


PropertiesCreateDate Property Owner Property (Database Objects)
ID Property Text Property
Name Property


MethodsBindToColumn Method Remove Method (Objects)
BindToDatatype Method Script Method
ListBoundColumns Method UnbindFromColumn Method
ListBoundDatatypes Method UnbindFromDatatype Method


Remarks
SQL Server offers several mechanisms for ensuring data integrity. A SQL Server rule is a Transact-SQL condition_expression syntax element that defines a data-integrity constraint. A rule can be bound to a column or user-defined data type. condition_expression is executed to validate data for a single column when a value is inserted into the column bound by the rule. For more information, see CREATE RULE.

With the Rule object, you can:

Create a SQL Server rule that defines an integrity constraint.


Bind an existing SQL Server rule to a column or user-defined data type.


Remove the constraint from a column or user-defined data type by unbinding a SQL Server rule.


Remove a SQL Server rule definition from a SQL Server database.


Generate a Transact-SQL script to create the rule represented by the object.
The Name property of a Rule object uses the SQL Server data type sysname. The value of the Name property must be unique for a database.

After you have created the rule, use the BindToColumn and BindToDatatype methods of the Rule object to apply the constraint to SQL Server columns and user-defined data types.

To create a SQL Server rule

Create a Rule object.


Set the Name property.


Set the Text property with the Transact-SQL script that validates data integrity for the columns bound by the rule.


Add the Rule object to the Rules collection of a connected Database object.
To remove a rule from a SQL Server database

Get the referring Rule object from the Rules collection of a connected Database object.


Use the ListBoundColumns and ListBoundDatatypes methods to determine affected SQL Server columns and user-defined data types.


Use the UnbindFromColumn and UnbindFromDatatype methods to remove the constraint from columns and user-defined data types bound by the rule.


Use the Remove method of the Rule object to remove it from the SQL Server database.


Note The Rule object is compatible with instances of SQL Server 2000 and SQL Server version 7.0. However, the Rule2 object extends the functionality of the Rule object for use with features that are new in SQL Server 2000.

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧