有什么办法可以将“全部”转换为“所有”吗?保存时字符串变为大写

发布于 2024-12-13 13:01:45 字数 125 浏览 0 评论 0原文

在将它们写入数据库之前,我需要将所有字符串转换为大写。有没有办法告诉 sql server 2008 自动执行此操作?我的意思是,sql server 2008 可以在保存字符串时将它们转换为大写吗?或者,我必须以编程方式执行此操作吗?

I need convert all strings to uppercase before to write them into the database. Is there any way to tell sql server 2008 to do this automatically? I mean, can sql server 2008 convert my strings to uppercase when they are saved? Or, do I have to do it programatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

晨与橙与城 2024-12-20 13:01:45

除非您可以更改 INSERT 和 UPDATE,否则您将需要触发器。

或者,如果您使用存储过程,则可以对参数发出 UPPER。

我还会考虑使用区分大小写的排序规则进行 CHECK 约束,以确保 UPPER(col) = col 以防万一您错过任何内容,或者至少错过一些常规检查

Unless you can change your INSERTs and UPDATEs, you'll need a trigger.

Or if you use stored procedures, you can issue UPPER on the parameters.

I'd also consider CHECK constraints with a case sensitive collation to ensure that UPPER(col) = col too in case you miss anything, or at least some regular checks

伪装你 2024-12-20 13:01:45

尝试:

INSERT INTO <Column NAme> VALUES (Upper('Your Value'));

try:

INSERT INTO <Column NAme> VALUES (Upper('Your Value'));
指尖上的星空 2024-12-20 13:01:45

一种方法是在桌子上放置一个触发器:

create trigger settouppercase
        on mytable
        instead of insert, update
as begin
    delete from mytable where mycolumnid in (select mycolumnid from deleted)

    select mycolumnid, upper(mycolumn) as mycolumn into #upcased from inserted

    insert into mytable(mycolumnid, mycolumn)
    select mycolumnid, mycolumn from #upcased
end

One way to do it is by putting a trigger on the table:

create trigger settouppercase
        on mytable
        instead of insert, update
as begin
    delete from mytable where mycolumnid in (select mycolumnid from deleted)

    select mycolumnid, upper(mycolumn) as mycolumn into #upcased from inserted

    insert into mytable(mycolumnid, mycolumn)
    select mycolumnid, mycolumn from #upcased
end
她说她爱他 2024-12-20 13:01:45

试试这个:

CREATE TRIGGER ToUpperCase
        ON tblUsers
        AFTER INSERT, UPDATE
AS
BEGIN

    UPDATE  tblUsers
    SET     UserName = UPPER(UserName)
    WHERE   UserId IN (SELECT UserId FROM inserted)

END

Try this:

CREATE TRIGGER ToUpperCase
        ON tblUsers
        AFTER INSERT, UPDATE
AS
BEGIN

    UPDATE  tblUsers
    SET     UserName = UPPER(UserName)
    WHERE   UserId IN (SELECT UserId FROM inserted)

END
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文