Linux中国  设为主页
 收藏本站
 
当前位置: > 首页 ->数据库应用 ->SQL Server ->SQL Server的Collate语句需注意
  相关分类: 
Access
DB2
Mysql
Oracle
PostgreSQL
SQL Server
Sybase
其他数据库
  站内搜索: 
热门文章排行
热门文章排行 SQLServer2005的一般部署步骤 (04-23)
SQL server 2005安装问题汇总(06-03)
[SQL Server]2005 Express Edition概(04-23)
用MS SQL Reporting Services生成报(04-17)
50种方法巧妙优化你的SQL Server数据(04-17)
精采文章排行
精采文章排行 教你如何在SQL Server计算机列和平均(06-29)
SQL Server数据库搭建农村信息化的方(06-29)
让VB实现SQL Server 2000存储过程调(06-29)
SQL Server数据库搭建农村信息化的方(06-29)
SQL Server 2005分析服务 统一整合视(06-29)
  ·如何在SQL Server中构建并利用UDF表格 ·使用T-SQL操作面试SQL Server开发人员 ·课程讲解 如何使用SQL Server校勘功能 ·SQL Server从安装到建库为新手寻找捷径 ·如何使用SQL Server数据库嵌套子查询 ·问题解决:SQL Server 2005无法重新安装 ·精细分析 SQL server服务器的内存配置 ·如何获取SQL Server数据库元数据的方法 ·用实例分析如何整理SQL Server输入数据

SQL Server的Collate语句需注意

作者:Webmaster   来源:knowsky    点击:   日期:2007-04-23 [收藏] [投稿]

  IE是否经常中毒?推荐您

汗,今天被Sql Server的Collate子句大玩了一把,看在线帮助不仔细!让自己绕了一个大圈,以后看MS帮助可要仔细了,事情是这样的:

下午,老大给我们发来一段SQL Script,要我们测试,看有没有错误,如有,请提出!整个Script全部在这里!

我当时就将这段脚本拉进了查询分析器,一执行,呵呵,根本没错啊!那老大为什么要发这样的邮件出来呢?于是我又切换了几个database,也没有什么问题,正当我准备测试完这一个database就放弃测试退出的时候,问题来了。错误消息如下:

Server: Msg 446, Level 16, State 9, Line 61

Cannot resolve collation conflict for equal to operation.

呵呵,有困难,找警察,咱有难,就找online啦。按下F1,键入collation,最后定位至See also中的Collate,查到帮助文件如下(不好意思,我只是将sql server2000 的在线帮助源封不动的复制了一下,当然在我当时没有看仔细的那一句我变换了颜色,各位朋友也请不要犯同样的错误为好。呵呵):

COLLATE

A clause that can be applied to a database definition or a column definition to define the collation, or to a character string expression to apply a collation cast.

Syntax

COLLATE < collation_name >

< collation_name > :: =

{ Windows_collation_name } | { SQL_collation_name }

Arguments

collation_name

Is the name of the collation to be applied to the expression, column definition, or database definition. collation_name can be only a specified Windows_collation_name or a SQL_collation_name.

Windows_collation_name

Is the collation name for Windows collation. See Windows Collation Names.

SQL_collation_name

Is the collation name for a SQL collation. See SQL Collation Names.

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 collation of the database. You can also specify a collation when you create a database using SQL Server Enterprise Manager. If you do not specify a collation, the database is assigned the default collation of the SQL Server instance.

Creating or altering a table column.

You can specify collations for each character string column using the COLLATE clause of the CREATE TABLE or ALTER TABLE statement. You can also specify a collation when you create a table using SQL Server Enterprise Manager. If you do not specify a collation, the column is assigned the default collation of the database.

You can also use the database_default option in the COLLATE clause to specify that a column in a temporary table use the collation default of the current user database for the connection instead of tempdb.

Casting the collation of an expression.

You can use the COLLATE clause to cast a character expression to a certain collation. Character literals and variables are assigned the default collation of the current database. Column references are assigned the definition collation of the column. For the collation of an expression, see Collation Precedence.

The collation of an identifier depends on the level at which it is defined. Identifiers of instance-level objects, such as logins and database names, are assigned the default collation of the instance. Identifiers of objects within a database, such as tables, views, and column names, are assigned the default collation of the database. For example, two tables with names differing only in case may be created in a database with case-sensitive collation, but may not be created in a database with case-insensitive collation.

Variables, GOTO labels, temporary stored procedures, and temporary tables can be created when the connection context is associated with one database, and then referenced when the context has been switched to another database. The identifiers for variables, GOTO labels, temporary stored procedures, and temporary tables are in the default collation of the instance.

The COLLATE clause can be applied only for the char, varchar, text, nchar, nvarchar, and ntext data types.

Collations are generally identified by a collation name. The exception is in Setup where you do not specify a collation name for Windows collations, but instead specify the collation designator, and then select check boxes to specify binary sorting or dictionary sorting that is either sensitive or insensitive to either case or accents.

You can execute the system function fn_helpcollations to retrieve a list of all the valid collation names for Windows collations and SQL collations:

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<

上一页12 下一页

上一篇:MS SQL Server中数据的磁带备份与恢复   下一篇:SQL Server Express Edition Server
文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论

   相关文章:
·精细讲述SQL Server数据库备份多种方法

   文章评论:(1条)
  
 请留名: 匿名评论   点击查看所有评论 论坛讨论
 

 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。