What are the advantages and disadvantages of explicitly specifying collation in table creation scripts?

℡╲_俬逩灬. 提交于 2019-12-10 21:09:56

问题


When creating a table, the COLLATE clause is optional. So, in:

CREATE TABLE T1 (
  F1 varchar(50) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL,
  F2 varchar(50) NOT NULL
)

the collation of F2 will be determined by the database default.

In the past our team always used the default collation. However, we now have a few columns where we need to explicitly specify collation. We are considering whether to change our standard to always specify collation and looking for any additional information that may help in this decision.

So:

  • What are the advantages/disadvantages of always specifying collation?
  • Are there any gotchas we need to watch out for if we always specify collation?

Possibly relevant additional information:

  • We deploy to multiple clients, and not all clients will be upgraded at the same time.
  • Some clients do have different collation configurations on their servers.
  • Our applications use Ansi strings, and any consideration of Unicode is a very long way away.
  • We use MS SQL Server 2005 and up (although I would prefer to keep the question general to any platform supporting collations if possible).

Please Note: This question is not asking about how to resolve collation conflicts, or change existing server/database/column collations. (There are plenty of those already.)


回答1:


You are building an application that deploys on client machines. You should be explicit about your collations.

For instance, the default collation is case insensitive. If the client -- for whatever reason -- prefers to have case sensitivity be the default in their database, then comparisons will differ on different machines.

You also have the issue of debugging. If the client is getting results in one sequential order, your test/development system may get them in a different order. This can hamper debugging and customer support.

In the end, it is probably better to have consistent software on your side for debugging, maintenance, and support. If a particular client needs data in a different format, then customize the system for that client.




回答2:


there is no point to specify colation if it is tha same as the database's colation (the default). You should do what you did on your example only if you want to store the data on F1 on a different collation



来源:https://stackoverflow.com/questions/11578591/what-are-the-advantages-and-disadvantages-of-explicitly-specifying-collation-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!