汗,今天被Sql Server的Collate子句大玩了一把,看在线帮助不仔细!让自己绕了一个大圈,以后看MS帮助可要仔细了,事情是这样的:
下午,老大给我们发来一段SQL Script,要我们测试,看有没有错误,如有,请提出!整个Script全部在这里!
我当时就将这段脚本拉进了查询分析器,一执行,呵呵,根本没错啊!那老大为什么要发这样的邮件出来呢?于是我又切换了几个database,也没有什么问题,正当我准备测试完这一个database就放弃测试退出的时候,问题来了。错误消息如下:
Server: Msg 446, Level 16, State 9, Line 61
Cannot resolve collati>呵呵,有困难,找警察,咱有难,就找>COLLATE
A clause that can be applied to a database definiti>Syntax
COLLATE < collati>< collati>{ Windows_collati>Arguments
collati>Is the name of the collati>Windows_collati>Is the collati>SQL_collati>Is the collati>Remarks
The COLLATE clause can be specified at several levels, including the following:
Creating or altering a database.
You can use the COLLATE clause of the CREATE DATABASE or ALTER DATABASE statement to specify the default collati>Creating or altering a table column.
You can specify collati>You can also use the database_default opti>Casting the collati>You can use the COLLATE clause to cast a character expressi>The collati>Variables, GOTO labels, temporary stored procedures, and temporary tables can be created when the c>The COLLATE clause can be applied >Collati>You can execute the system functi>SELECT *FROM ::fn_helpcollati>SQL Server can support >Specifying a default collati>Specifying a collati>When restoring or attaching a database, the default collati>Code page translati>If the collati>当时,我承认,我确实大致看完了全篇了,心里明白是排序规则的原因,导致了错误信息的出现。使用collate语句强制指定排序规则是可以解决的,于是我在老大的代码上的每个字串类型的字段后面都加上了 collate Chinese_PRC_CI_AS ,然后F5运行,faint...,问题照旧。于是改为:collate SQL_Latin1_General_CP1_CI_AS,嗯,问题解决,正当以为就这样可以解决的时候,我又试了一下没加之前没错的database,faint...,他们出现了同样的错误信息,难道是拆东墙补西墙。不行, 问题没有解决,于是,我也上QQ群发问了,也不知是因为今天是周末还是什么原因,总之没有一个人回答我。最后实在没有办法,只好自己再回来看上面那段其实我并不喜欢的帮助啦(因为是英文嘛!呵呵...),当我看到
You can also use the database_default opti>着实把我喜了一把。马上改用collate database_default,嗯,一个通过、两个通过、三个通过....
OK,终于解决,松了一口气。
将这件事post上来,一是对自己作个警示:以后看帮助真的要仔细点。二是希望朋友不要犯类似的低级错误,以免浪费无谓的时间。如果要查看源码sql script,请点击这里下载。是提取database的属性的哦。
无忧CMS,5ucms.org建站仿站首选!
上一篇:5ucms培训,如何用hash关键字提高数据库性能 下一篇:5ucms模版,SQL Server存储过程编写经验和优化 |
|
本站声明:本网站所载文章等内容,目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权及其它问题,请在30日内与本网联系(Email:3876307#qq.com),我们将在第一时间删除内容。若原创内容转载请注明出处。 5ucms培训,SQL Server的Collate语句需注意的关键词: |