av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

SQL Server的Collate語句需注意

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

汗,今天被Sql Server的Collate子句大玩了一把,看在線幫助不仔細(xì)!讓自己繞了一個大圈,以后看MS幫助可要仔細(xì)了,事情是這樣的:下午,老大給我們發(fā)來一段SQL Script,要我們測試,看有沒有錯誤,如有,請?zhí)岢觯≌麄€Script全部在這里!我當(dāng)時就將這段腳本拉進(jìn)了查詢分析器,一執(zhí)行,呵呵,根本沒錯啊!那老大為什么要發(fā)這樣的郵件出來呢?于是我又切換了幾個database,也沒有什么問題,正當(dāng)我準(zhǔn)備測試完這一個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 的在線幫助源封不動的復(fù)制了一下,當(dāng)然在我當(dāng)時沒有看仔細(xì)的那一句我變換了顏色,各位朋友也請不要犯同樣的錯誤為好。呵呵):

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.

當(dāng)時,我承認(rèn),我確實(shí)大致看完了全篇了,心里明白是排序規(guī)則的原因,導(dǎo)致了錯誤信息的出現(xiàn)。使用collate語句強(qiáng)制指定排序規(guī)則是可以解決的,于是我在老大的代碼上的每個字串類型的字段后面都加上了 collate Chinese_PRC_CI_AS; ,然后F5運(yùn)行,faint...,問題照舊。于是改為:collate SQL_Latin1_General_CP1_CI_AS,嗯,問題解決,正當(dāng)以為就這樣可以解決的時候,我又試了一下沒加之前沒錯的database,faint...,他們出現(xiàn)了同樣的錯誤信息,難道是拆東墻補(bǔ)西墻。不行, 問題沒有解決,于是,我也上QQ群發(fā)問了,也不知是因?yàn)榻裉焓侵苣┻€是什么原因,總之沒有一個人回答我。最后實(shí)在沒有辦法,只好自己再回來看上面那段其實(shí)我并不喜歡的幫助啦(因?yàn)槭怯⑽穆铮『呛?..),當(dāng)我看到

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.

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

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

標(biāo)簽: Sql Server 數(shù)據(jù)庫
主站蜘蛛池模板: 久久久久国产精品夜夜夜夜夜 | 欧美日韩精品久久久免费观看 | 日韩在线免费播放 | 黄色成人av | 免费在线看a | 少妇bbw搡bbbb搡bbbb | 欧美视频精品 | 日本一区二区不卡 | 亚洲三级免费 | 国产日韩一区二区 | av网站免费在线观看 | 亚洲一区免费视频 | 三级在线看 | 三级黄色在线观看 | 成人在线观看网站 | 中文字幕日韩欧美 | 五月天婷婷在线观看 | 天天干天天曰 | 视频一区在线播放 | 日本欧美久久久久免费播放网 | 亚洲欧美另类在线 | 国产成人在线视频 | www.四虎影视 | 日韩一二区 | a视频| 九九热在线播放 | 黄色片免费在线观看 | 午夜激情网站 | 国产成人在线免费观看 | 九九热在线精品 | 欧美色综合天天久久综合精品 | 欧美vieox另类极品 | 日本免费在线 | 日韩一级免费视频 | 欧美日韩三区 | 国产激情久久久 | 日韩手机看片 | 国产成人精品av在线观 | 91免费视频 | 久久人人爱 | 欧美亚洲在线观看 |