You are here: Re: uppercase trigger « MsSQL Server « IT news, forums, messages
Re: uppercase trigger

Posted by Erland Sommarskog on 07/12/05 12:16

Fernand St-Georges (fernand.st-georges@videotron.ca) writes:
> How can I create a trigger that obliges UPPERCASE of a field in the
> database?

CREATE TRIGGER uppercase_tri ON tbl FOR INSERT, UPDATE AS
IF UPDATE(uppercase_col)
BEGIN
UPDATE tbl
SET uppercase_col = upper(i.uppercase_col)
FROM tbl t
JOIN inserted i ON t.keycol = i.keycol
END

If the data comes from GUI entry, I tend however to agree with MGFoster,
that this should be done in the client, because it's confusing for the
user type 'nisse' and next time he looks at the data he sees 'NISSE'.

In this case you may still want enforce the business rule in the database.
To this end a constraint would do. If you are using a case-sensitive
collation it's as easy as:

col varchar(20) NULL
CONSTRAINT tbl_col_uppercase (CHECK col = upper(col))

If you use a case-insensitive collation, it's trickier. But this should
work:

col varchar(20) NULL
CONSTRAINT tbl_col_uppercase
(CHECK col COLLATE Finnish_Swedish_CS_AS = upper(col))

Instead of Finnish_Swedish_CS_AS, use the case-sensitive collation that
matches your case-insensitive collation.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

 

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

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