电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

SQL Server的Collate語句需注意

瀏覽:179日期:2023-10-31 10:32:57

汗,今天被Sql Server的Collate子句大玩了一把,看在線幫助不仔細!讓自己繞了一個大圈,以后看MS幫助可要仔細了,事情是這樣的:下午,老大給我們發來一段SQL Script,要我們測試,看有沒有錯誤,如有,請提出!整個Script全部在這里!我當時就將這段腳本拉進了查詢分析器,一執行,呵呵,根本沒錯啊!那老大為什么要發這樣的郵件出來呢?于是我又切換了幾個database,也沒有什么問題,正當我準備測試完這一個database就放棄測試退出的時候,問題來了。錯誤消息如下:Server: Msg 446, Level 16, State 9, Line 61Cannot resolve collation conflict for equal to operation.呵呵,有困難,找警察,咱有難,就找online啦。按下F1,鍵入collation,最后定位至See also中的Collate,查到幫助文件如下(不好意思,我只是將sql server2000 的在線幫助源封不動的復制了一下,當然在我當時沒有看仔細的那一句我變換了顏色,各位朋友也請不要犯同樣的錯誤為好。呵呵):

COLLATEA 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.

SyntaxCOLLATE < collation_name >

< collation_name > :: = { Windows_collation_name } | { SQL_collation_name }

Argumentscollation_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. RemarksThe 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:

SELECT *FROM ::fn_helpcollations()SQL Server can support only code pages that are supported by the underlying operating system. When you perform an action that depends on collations, the SQL Server collation used by the referenced object must use a code page supported by the operating system running on the computer. These actions can include:

Specifying a default collation for a database when you create or alter the database.

Specifying a collation for a column when creating or altering a table.

When restoring or attaching a database, the default collation of the database and the collation of any char, varchar, and text columns or parameters in the database must be supported by the operating system. Code page translations are supported for char and varchar data types, but not for text data type. Data loss during code page translations is not reported.

If the collation specified or the collation used by the referenced object, uses a code page not supported by Windows®, SQL Server issues error. For more information, see the Collations section in the SQL Server Architecture chapter of the SQL Server Books Online.

當時,我承認,我確實大致看完了全篇了,心里明白是排序規則的原因,導致了錯誤信息的出現。使用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 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.

著實把我喜了一把。馬上改用collate database_default,嗯,一個通過、兩個通過、三個通過....OK,終于解決,松了一口氣。

將這件事post上來,一是對自己作個警示:以后看幫助真的要仔細點。二是希望朋友不要犯類似的低級錯誤,以免浪費無謂的時間。如果要查看源碼sql script,請點擊這里下載。是提取database的屬性的哦。

標簽: Sql Server 數據庫
主站蜘蛛池模板: 口信网(kousing.com) - 行业资讯_行业展会_行业培训_行业资料 | 中央空调温控器_风机盘管温控器_智能_液晶_三速开关面板-中央空调温控器厂家 | 发电机组|柴油发电机组-批发,上柴,玉柴,潍柴,康明斯柴油发电机厂家直销 | 衡阳耐适防护科技有限公司——威仕盾焊接防护用品官网/焊工手套/焊接防护服/皮革防护手套 | 厂房出租-厂房规划-食品技术-厂房设计-厂房装修-建筑施工-设备供应-设备求购-龙爪豆食品行业平台 | 压力喷雾干燥机,喷雾干燥设备,柱塞隔膜泵-无锡市闻华干燥设备有限公司 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 中央空调维修、中央空调保养、螺杆压缩机维修-苏州东菱空调 | 红立方品牌应急包/急救包加盟,小成本好项目代理_应急/消防/户外用品加盟_应急好项目加盟_新奇特项目招商 - 中红方宁(北京) 供应链有限公司 | 板框压滤机-隔膜压滤机配件生产厂家-陕西华星佳洋装备制造有限公司 | PTFE接头|聚四氟乙烯螺丝|阀门|薄膜|消解罐|聚四氟乙烯球-嘉兴市方圆氟塑制品有限公司 | 超声波破碎仪-均质乳化机(供应杭州,上海,北京,广州,深圳,成都等地)-上海沪析实业有限公司 | 螺纹三通快插接头-弯通快插接头-宁波舜驰气动科技有限公司 | 组织研磨机-高通量组织研磨仪-实验室多样品组织研磨机-东方天净 传递窗_超净|洁净工作台_高效过滤器-传递窗厂家广州梓净公司 | 首页|专注深圳注册公司,代理记账报税,注册商标代理,工商变更,企业400电话等企业一站式服务-慧用心 | 智能电表|预付费ic卡水电表|nb智能无线远传载波电表-福建百悦信息科技有限公司 | 彩超机-黑白B超机-便携兽用B超机-多普勒彩超机价格「大为彩超」厂家 | 步进_伺服_行星减速机,微型直流电机,大功率直流电机-淄博冠意传动机械 | 成都软件开发_OA|ERP|CRM|管理系统定制开发_成都码邻蜀科技 | 温州富欧金属封头-不锈钢封头厂家| 低气压试验箱_高低温低气压试验箱_低气压实验箱 |林频试验设备品牌 | 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 全钢实验台,实验室工作台厂家-无锡市辰之航装饰材料有限公司 | 电动葫芦|防爆钢丝绳电动葫芦|手拉葫芦-保定大力起重葫芦有限公司 | 卫浴散热器,卫浴暖气片,卫生间背篓暖气片,华圣格浴室暖气片 | 定硫仪,量热仪,工业分析仪,马弗炉,煤炭化验设备厂家,煤质化验仪器,焦炭化验设备鹤壁大德煤质工业分析仪,氟氯测定仪 | 郑州水质检测中心_井水检测_河南废气检测_河南中环嘉创检测 | ZHZ8耐压测试仪-上海胜绪电气有限公司 | 磁棒电感生产厂家-电感器厂家-电感定制-贴片功率电感供应商-棒形电感生产厂家-苏州谷景电子有限公司 | 成都离婚律师|成都结婚律师|成都离婚财产分割律师|成都律师-成都离婚律师网 | 小型气象站_便携式自动气象站_校园气象站-竞道气象设备网 | 太空舱_民宿太空舱厂家_移动房屋太空舱价格-豪品建筑 | 洛阳永磁工业大吊扇研发生产-工厂通风降温解决方案提供商-中实洛阳环境科技有限公司 | 广州中央空调回收,二手中央空调回收,旧空调回收,制冷设备回收,冷气机组回收公司-广州益夫制冷设备回收公司 | 南京PVC快速门厂家南京快速卷帘门_南京pvc快速门_世界500强企业国内供应商_南京美高门业 | 河南空气能热水器-洛阳空气能采暖-洛阳太阳能热水工程-洛阳润达高科空气能商行 | 万师讲师网-优质讲师培训师供应商,讲师认证,找讲师来万师 | 成都亚克力制品,PVC板,双色板雕刻加工,亚克力门牌,亚克力标牌,水晶字雕刻制作-零贰捌广告 | SOUNDWELL 编码器|电位器|旋转编码器|可调电位器|编码开关厂家-广东升威电子制品有限公司 | 天长市晶耀仪表有限公司| 大_小鼠elisa试剂盒-植物_人Elisa试剂盒-PCR荧光定量试剂盒-上海一研生物科技有限公司 |