SSMS 中的区分大小写

发布于 2024-07-30 19:52:02 字数 4251 浏览 3 评论 0原文

我的 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

[EDIT] 经过多次尝试不同的组合后,突然间,数据库不再区分大小写。 魔法!?

My SQL Server Management Studio suddenly went case sensitive on me. The database and server are both set to case insensitive

SQL_Latin1_General_CP1_CI_AS

I run queries like

Select * From mytable 

and I get "invalid object name"

but if i run

select * from MyTable

i get data!!

I created a new database and created a dummy table and successfully ran case insensitive queries over there.

Any ideas what I can look into here?

EDITED

Here is the output of the statments from the answer given by @Sam. It is very strange that the Server and the Database both have case insensitivity defined, but the individual columns are case sensitive. The Create Table statements do not contain collation information - only collation
Question: Why is the query using the table name case sensitive when the database is 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

[EDIT]
After several attempts of trying different combinations, suddenly, the database is no longer CaseSensitive. Magic!?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

無心 2024-08-06 19:52:02

很奇怪。 也许这些命令可以帮助您追踪问题:

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 选项 打开 - 尽管我从未听说过 CS 选项。

也许尝试通过 SQLCMD 运行查询,看看会发生什么。

Very strange. Perhaps these commands could help you track the issue down:

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')

My first thought is that you had a SET option switched on - although I had never heard of one for CS.

Perhaps try running a query through SQLCMD and see what happens.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文