SSMS 中的大小写敏感性
Posted
技术标签:
【中文标题】SSMS 中的大小写敏感性【英文标题】:Case Sensitivity in SSMS 【发布时间】:2009-08-11 19:49:28 【问题描述】:我的 SQL Server Management Studio 突然区分大小写。数据库和服务器都设置为不区分大小写
SQL_Latin1_General_CP1_CI_AS
我运行类似的查询
Select * From mytable
我得到“无效的对象名称”
但是如果我跑了
select * from MyTable
我得到数据!!
我创建了一个新数据库并创建了一个虚拟表,并在那里成功地运行了不区分大小写的查询。
我可以在这里研究什么?
已编辑
这是@Sam 给出的答案的输出。很奇怪,服务器和数据库都定义了不区分大小写,但各个列都区分大小写。 Create Table 语句不包含排序规则信息 - 仅排序规则 问题:为什么数据库是CI时使用表名的查询区分大小写
Server Level Collation
-----------------------------
SQL_Latin1_General_CP1_CI_AS
Database Level Collation
------------------------------
SQL_Latin1_General_CP1_CI_AI
Name Owner Type Created_datetime
------------- ------ ---------- -----------------------
ProfitCenter dbo user table 2009-08-06 13:02:56.180
Column_name Type Length Collation
---------------------------- ----------- ------- -------------------------------
ProfitCenterID int 4 NULL
HierarchyNodeID int 4 NULL
ProfitCenterStatusID int 4 NULL
BICProfitCenterNumber varchar 10 SQL_Latin1_General_CP1_CS_AS
ProfitCenterName varchar 255 SQL_Latin1_General_CP1_CS_AS
BICDistrictNumber char 10 SQL_Latin1_General_CP1_CS_AS
BICClientNumber varchar 10 SQL_Latin1_General_CP1_CS_AS
ManagerEmail varchar 255 SQL_Latin1_General_CP1_CS_AS
ManagerFirstName varchar 255 SQL_Latin1_General_CP1_CS_AS
ManagerLastName varchar 255 SQL_Latin1_General_CP1_CS_AS
PCOpenDate datetime 8 NULL
PCCloseDate datetime 8 NULL
LastDayOperation datetime 8 NULL
ContractType char 10 SQL_Latin1_General_CP1_CS_AS
ContractTypeDesc varchar 50 SQL_Latin1_General_CP1_CS_AS
CBSPCTypeCode char 3 SQL_Latin1_General_CP1_CS_AS
CBSPCTypeDesc varchar 50 SQL_Latin1_General_CP1_CS_AS
SBCSPCFlag char 1 SQL_Latin1_General_CP1_CS_AS
SBCSPCGroupCode char 3 SQL_Latin1_General_CP1_CS_AS
SBCSPCRate decimal 9 NULL
SBCSPCComponent varchar 10 SQL_Latin1_General_CP1_CS_AS
SBCSPCAccount varchar 10 SQL_Latin1_General_CP1_CS_AS
PaymentTerms varchar 25 SQL_Latin1_General_CP1_CS_AS
RiskRate varchar 25 SQL_Latin1_General_CP1_CS_AS
RiskRateCapFlag varchar 3 SQL_Latin1_General_CP1_CS_AS
RiskCapRate numeric 9 NULL
BICAddedDateTime datetime 8 NULL
BICUpdatedDateTime datetime 8 NULL
Identity Seed Increment Not For Replication
--------------- ----- ---------- -------------------
ProfitCenterID 1 1 1
RowGuidCol
------------------------------
No rowguidcol column defined.
Data_located_on_filegroup
--------------------------
PRIMARY
index_name index_description index_keys
------------------------------------------ ---------------------------------------- ----------------------
ProfitCenter_PK clustered, unique located on PRIMARY ProfitCenterID
ProfitCenter_Unique_BICProfitCenterNumber nonclustered, unique located on PRIMARY BICProfitCenterNumber
No constraints are defined on object 'dbo.ProfitCenter', or you do not have permissions.
No foreign keys reference table 'dbo.ProfitCenter', or you do not have permissions on referencing tables.
No views with schema binding reference table 'dbo.ProfitCenter'.
Server default collation
----------------------------------------------------------------
Latin1-General, case-insensitive, accent-sensitive,
kanatype-insensitive, width-insensitive for Unicode Data,
SQL Server Sort Order 52 on Code Page 1252 for non-Unicode Data
[编辑] 经过多次尝试不同组合的尝试,突然间,数据库不再区分大小写。魔法!?
【问题讨论】:
不是你喜欢看的魔法类型,是吗?还有其他人可以访问数据库吗? 正确!我绝对不喜欢软件中无法解释的谜团。有问题的数据库在我的机器上,除了我的域管理员之外,我是工作站上唯一的管理员。 【参考方案1】:很奇怪。也许这些命令可以帮助您追踪问题:
SELECT SERVERPROPERTY('Collation') AS 'Server Level Collation'
To see your default database collation:
SELECT DATABASEPROPERTYEX('Pubs', 'Collation') AS 'Database Level Collation'
To see column level collations of Customers table:
EXEC sp_help 'dbo.Customers'
To see server level collation settings in SQL Server 2000 as well as the previous versions:
EXEC sp_helpsort
To a listing of all available collations in SQL Server 2000:
SELECT * FROM ::fn_helpcollations()
For further information about specific collations:
SELECT COLLATIONPROPERTY('German_PhoneBook_CI_AS', 'CodePage')
SELECT COLLATIONPROPERTY('French_CI_AS', 'LCID')
SELECT COLLATIONPROPERTY('Latin1_General_CI_AS', 'ComparisonStyle')
我的第一个想法是您打开了SET option - 尽管我从未听说过用于 CS 的。
也许尝试通过SQLCMD 运行查询,看看会发生什么。
【讨论】:
好答案。不过有一个小问题:为了清楚起见,应该有 2 个数据库排序规则检查,一个用于“MYDB”,一个用于“模型”(这是新数据库的默认排序规则的来源)。以上是关于SSMS 中的大小写敏感性的主要内容,如果未能解决你的问题,请参考以下文章