简体   繁体   English

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

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

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列区分大小写,但不是所有其他区域

ALTER TABLE ALTER COLUMN allows 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) (整理可能不正确)

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. 将insert和update触发器放在表上,以便它们存储在您想要的情况下。
  • 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. 在SQL Server中可能有更快的方法,但是你应该小心将工作量推入SELECT语句的解决方案 - 它们从不能很好地扩展。 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. 作为插入和更新的一部分,这几乎总是更好,因为这是数据更改的唯一时间 - 这样做可以最大限度地减少额外的工作量。

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和宽度敏感是什么意思

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM