You are here: Re: sql rules and udt « MsSQL Server « IT news, forums, messages
Re: sql rules and udt

Posted by Dan Guzman on 09/06/07 12:17

> hello, i've just started playing around with rules and udt
> is it possible to alter rule?

You'll need to recreate the rule, which requires that you unbind, drop,
create and bind again. See sample script at the end of this post.

> are rules 'slower' compared to check constraint?

I haven't used rules for many years nor have I seen a performance comparison
between rules and CHECK constraints. However, I would not use rules for new
development. Below is an excerpt from the SQL 2005 Books Online:

<Excerpt
href="ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/b016a289-3a74-46b1-befc-a13183be51e4.htm">

CREATE RULE will be removed in a future version of Microsoft SQL Server.
Avoid using CREATE RULE in new development work, and plan to modify
applications that currently use it. We recommend that you use check
constraints instead. Check constraints are created by using the CHECK
keyword of CREATE TABLE or ALTER TABLE. For more information, see CHECK
Constraints.

</Excerpt>


USE tempdb
GO

EXEC sp_addtype 'mytype', 'int'
GO

CREATE RULE RUL_mytype AS (@mytype > 0)
GO

EXEC sp_bindrule 'RUL_mytype', 'mytype'
GO

CREATE TABLE dbo.MyTable
(
col1 mytype NOT NULL
)
GO

INSERT INTO dbo.MyTable VALUES(1)
INSERT INTO dbo.MyTable VALUES(-1)
GO

EXEC sp_unbindrule 'mytype', 'RUL_mytype'
GO

DROP RULE RUL_mytype
GO

CREATE RULE RUL_mytype AS (@mytype < 0)
GO

EXEC sp_bindrule 'RUL_mytype', 'mytype'
GO

INSERT INTO dbo.MyTable VALUES(-1)
INSERT INTO dbo.MyTable VALUES(1)
GO

SELECT * FROM dbo.MyTable
GO


--
Hope this helps.

Dan Guzman
SQL Server MVP

"Nick Chan" <zzzxtreme@yahoo.com> wrote in message
news:1189076493.419195.7440@y42g2000hsy.googlegroups.com...
> hello, i've just started playing around with rules and udt
> is it possible to alter rule?
> are rules 'slower' compared to check constraint?
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация