SQL Server的Collate语句需注意

汗,今天被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.

时间: 2024-08-07 15:58:00

SQL Server的Collate语句需注意的相关文章

Win10下安装Sql Server 2014反复提示需安装.NET Framework 3.5 SP1的解决方案

一.首先安装.NET Framework 3.5 离线安装方式: 1.装载相对应的系统安装盘,我是Windows 10 x64 企业版,所以装载Windows 10 x64 企业版安装镜像ISO,盘符为H. 2.以管理员身份运行命令提示符(Win键+X键,选择命令提示符(管理员)),输入以下命令: dism.exe /online /enable-feature /featurename:NetFX3 /Source:H:\sources\sxs 等待部署完成即可. 在线安装方式: 1.打开控制

sql2005-关于sql server 2005 查询语句的问题

问题描述 关于sql server 2005 查询语句的问题 给出四条不同功能的查询语句,请问怎么用类似case语句的结构把它们连接起来形成一条语句,分情况显示查询结果? 解决方案 sql server 查询语句SQL Server 2005 CLR 调用Web Service需要注意的几个问题Sql Server 2005的datetime字段 在PHP中显示问题 解决方案二: 你先弄清楚他们的不同在哪,把这些条件用case区分 解决方案三: 一个表?还是多个表?一个表就where,多个表,需

Win10下安装Sql Server 2014反复提示需安装.NET Framework 3.5 SP1的解决方案_MsSql

一.首先安装.NET Framework 3.5 离线安装方式: 1.装载相对应的系统安装盘,我是Windows 10 x64 企业版,所以装载Windows 10 x64 企业版安装镜像ISO,盘符为H. 2.以管理员身份运行命令提示符(Win键+X键,选择命令提示符(管理员)),输入以下命令: dism.exe /online /enable-feature /featurename:NetFX3 /Source:H:\sources\sxs 等待部署完成即可. 在线安装方式: 1.打开控制

SQL Server阻塞查询语句

SQL Server阻塞查询语句  SQL Server的阻塞查询主要来自sys.sysprocesses.通常在处理时需要加入其它相关的视图或表,例如如sys.dm_exec_connections,sys.dm_exec_sql_text.通过如下几个语句的查询,可以找到阻塞的语句. 点击(此处)折叠或打开 SELECT BL.SPID BLOCKING_SESSION,        BL.BLOCKED BLOCKED_SESSION,        ST.TEXT BLOCKEDTEX

SQL SERVER中Case语句的用法

Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END --Case搜索函数 CASE WHEN sex = '1' THEN '男' WHEN sex = '2' THEN '女' ELSE '其他' END 这两种方式,可以实现相同的功能.简单Case函数的写法相对比较简洁,但是和Case搜索函数相比,功能方面会有些限制,比如写判断式. 还有一个需要

SQL Server中各种语句的完整语法

  下列语句部分是MS SQL语句,不可以在access中使用. SQL分类: DDL-数据定义语言(CREATE,ALTER,DROP,DECLARE) DML-数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL-数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK) 首先,简要介绍基础语句: 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:

SQL Server使用Merge语句当源表数据集为空时,无法进行查询的问题_MsSql

面举一个例子来具体说明一下: 有两个表SourceTable为登陆表,TargetTable为授权表,如果访问用户在登陆表中,更新授权表的授权级别,否则授权0表示游客.sql语句如下: --SourceTable为登陆表,TargetTable为授权表 --如果访问用户在登陆表中,更新授权表的授权级别,否则授权0表示游客. create table SourceTable(UserName nvarchar(10),Pwd int,[Level] int) create table Target

SQL Server对select语句返回多条记录给变量赋值时的处理情况

select|server|变量|语句 declare @user nvarchar(20)select @user='user1'use countme/*判断用户是否存在*/declare @userweek intselect @userweek=[week] from base where userid=@userselect @@rowcountif @@rowcount=0returnselect @userweek 最后的@userweek打印出来的结果就是记录用户名为user1的

SQL Server 数据库基本操作语句总结_MsSql

复制代码 代码如下: --sql基本操作 --创建数据库 create database Studets --创建表 create table student ( sno char(5), sname char(20), ssex char(2), sage smallint, sdept char(15) ) create table course ( cno char(3), cname char(30), cpno char(3), ccredit smallint ) create ta