如何在 sql 2005 或 2008 中使列区分大小写

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/805642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:53:42  来源:igfitidea点击:

How to make a column case sensitive in sql 2005 or 2008

sqlsql-serversql-server-2005sql-server-2008

提问by MichaelD

Is it possible to change the default collation based on a column? i want to make 1 column case sensitive but all the others not

是否可以根据列更改默认排序规则?我想让 1 列区分大小写,但所有其他列不区分

回答by Anton Gogolev

ALTER TABLE ALTER COLUMNallows to change collation for a single column:

ALTER TABLE ALTER COLUMN允许更改单列的排序规则:

alter table Foo alter column Bar ntext collate Latin1_General_CS_AS 

(collation might be incorrect)

(整理可能不正确)

回答by paxdiablo

I don't specifically know SQL Server, but the generally accepted DBMS practice (for compatibility) would be to either:

我并不特别了解 SQL Server,但普遍接受的 DBMS 实践(为了兼容性)是:

  • put insert and update triggers on the table so that they're stored in the case you want.
  • use generated columns to store another copy of the column in the case you want.
  • 将插入和更新触发器放在表上,以便将它们存储在您想要的情况下。
  • 使用生成的列在您想要的情况下存储该列的另一个副本。

There may be a faster way to do it in SQL Server but you should be careful of solutions that push workload into the SELECT statements - they never scale well. It's almost always better doing this as part of inserts and updates since that's the only time data changes - doing it that way minimizes the extra workload.

在 SQL Server 中可能有一种更快的方法来做到这一点,但您应该小心将工作负载推入 SELECT 语句的解决方案 - 它们永远无法很好地扩展。作为插入和更新的一部分这样做几乎总是更好,因为这是数据更改的唯一时间 - 这样做可以最大限度地减少额外的工作量。

回答by Bhavik Gada

The answer to your question is yes, already stated above by Anton Gogolev.

您的问题的答案是肯定的,上面已经由Anton Gogolev 说了

Additional Info:

附加信息:

Here is a how you can find list of Collation supported by your SQL Server based on its version.

以下是根据 SQL Server 的版本查找 SQL Server 支持的排序规则列表的方法。

select name, 
       COLLATIONPROPERTY(name, 'CodePage') as Code_Page, 
       description
from   sys.fn_HelpCollations()

what is the meaning of Kanatype Sensitive KS and width sensitive

Kanatype Sensitive KS 和宽度敏感是什么意思