SQL query field names in SQL Mgt Studio are case-sensitive

rsaritzky
Member Posts: 469
Hi:
In my Nav SQL databases running under SQL 2005 (3.60 database running under NAV 5.1 client), my queries require field names and table names to be case-correct, e.g. the following query will NOT work:
select * from [CRONUS USA, Inc_$G_L entry]
I receive an error: "Invalid object name 'CRONUS USA, Inc_$G_L entry'."
Notice that the table name is spelled with a lower-case "e" in the word 'entry'
However, if I use the correct-case spelling:
select * from [CRONUS USA, Inc_$G_L Entry]
.. the query works OK.
Similarly for field names, e.g.
select * from [CRONUS USA, Inc_$G_L Entry] where [G_L account No_] = '18100'
does not work ("account" is spelled with lower-case 'a'), but
select * from [CRONUS USA, Inc_$G_L Entry] where [G_L Account No_] = '18100'
works.
Is this related to the database collation sequence? The current collation sequence on the database is SQL_Latin1_General_CP1_CI_AS - case insensitive, Accent Sensitive as I read it (I didn't set up the databases).
Has anyone else had this experience?
Thx
Ron
In my Nav SQL databases running under SQL 2005 (3.60 database running under NAV 5.1 client), my queries require field names and table names to be case-correct, e.g. the following query will NOT work:
select * from [CRONUS USA, Inc_$G_L entry]
I receive an error: "Invalid object name 'CRONUS USA, Inc_$G_L entry'."
Notice that the table name is spelled with a lower-case "e" in the word 'entry'
However, if I use the correct-case spelling:
select * from [CRONUS USA, Inc_$G_L Entry]
.. the query works OK.
Similarly for field names, e.g.
select * from [CRONUS USA, Inc_$G_L Entry] where [G_L account No_] = '18100'
does not work ("account" is spelled with lower-case 'a'), but
select * from [CRONUS USA, Inc_$G_L Entry] where [G_L Account No_] = '18100'
works.
Is this related to the database collation sequence? The current collation sequence on the database is SQL_Latin1_General_CP1_CI_AS - case insensitive, Accent Sensitive as I read it (I didn't set up the databases).
Has anyone else had this experience?
Thx
Ron
Ron
0
Answers
-
I must correct myself. The NAV database's collation sequence is Latin1_General_CS_AS - case-sensitive, accent-sensitive.
Same question - does this control query field/table name case-sensitivity?
RonRon0 -
I think yes, it depends on the collation, but I am not sure if on DB collation or server collation (collation of master database).0
-
I've always thought that collation is about the data, not about the objects. I've never known otherwise than that field names have to be spelled correctly, which is weird because it does accept keywords in lower case.0
-
DenSter wrote:I've always thought that collation is about the data, not about the objects. I've never known otherwise than that field names have to be spelled correctly, which is weird because it does accept keywords in lower case.
I've always thought the same thing. And, for the non-NAV databases on the same server, I don't have the same issue - I can type the query in aNy cAsE tHaT I wAnT aNd iT sTiLL wOrKs <grin>.
I thought it might be my original 3.60 database, but I installed new NAV demo databases (both 5.1 and 2009) from CD and they behave the exact same way.
I also have 2 SQL 2005 server installs on separate machines - same behavior on both.Ron0 -
Collation is not about the data, but rather how the database engine reads and processes the data. Having a "case sensitive" colloation , or not, does not determine what data can be stored but rather how a particular database engine will read that data.There are no bugs - only undocumented features.0
-
Well, I just found this tidbit of information in Books Online:
"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 in a database, such as tables, views, and column names, are assigned the default collation of the database. For example, two tables with names that differ only in case can be created in a database that has case-sensitive collation, but cannot be created in a database that has case-insensitive collation."
So, in SQL 2005, table and field names are case-sensitive if the database collation is case-sensitive.
Thanks to everyone who responded anyway.
RonRon0 -
bbrown wrote:Collation is not about the data
I've always thought that the collation ONLY determines anything related to the data, and that the collation does not have an effect on how cases are evaluated when it comes to table/field names. So I've always assumed that SQL Server would consider [NAME] and [name] to be different fields, regardless of the collation. Because I am not a very accurate typist, I've taught myself years ago to always use object browsers, or to drag table/field/stored procedure names into the query window. For the past 8 years I don't think I've actually typed more than 5 fields names, so I've never had a problem with that particular issue.
In other words: if you always use the exact names, you will never have any problem with the case of the characters.0 -
DenSter wrote:bbrown wrote:Collation is not about the data
I've always thought that the collation ONLY determines anything related to the data, and that the collation does not have an effect on how cases are evaluated when it comes to table/field names. So I've always assumed that SQL Server would consider [NAME] and [name] to be different fields, regardless of the collation. Because I am not a very accurate typist, I've taught myself years ago to always use object browsers, or to drag table/field/stored procedure names into the query window. For the past 8 years I don't think I've actually typed more than 5 fields names, so I've never had a problem with that particular issue.
My reading of the Books Online and actual trying leads me to the conclusion that as far as table/field names, [NAME] and [name] CAN relate to the same object IF the collation sequence is case-insensitive. I'm a fast typist and a very slow mouser, so I type most queries. It wasn't an issue in SQL2000 - you could type queries in any case and it would work.
RonRon0 -
The problem is that the engine is sometime searching for the identifiers in the system tables in the database, it means using the collation for the data of this system table (something like searching for the field in Field system table in NAV ;-)) it means it is really data which are affected by the collation, even when it is "just" identifier of table or field...0
-
rsaritzky wrote:I'm a fast typist and a very slow mouser
In NAV development I use F5 to get fieldnames into my code, and I'm pretty quick at it. There must be shortcut keys in SQL Server, I just don't use it enough to figure them out.0 -
There's always the option of using the "Query Designer"There are no bugs - only undocumented features.0
-
Like I said:DenSter wrote:I just don't use it enough to figure them out.0
-
DenSter wrote:rsaritzky wrote:I'm a fast typist and a very slow mouser
In NAV development I use F5 to get fieldnames into my code, and I'm pretty quick at it. There must be shortcut keys in SQL Server, I just don't use it enough to figure them out.
A pretty cool tool for SQL is SQLPrompt from RedGate Software. They have a suite of tools for SQL called the SQL Toolbelt, but SQLPrompt is my favorite - it adds auto-complete to sql mgt studio, and has ways to automatically insert snippets. I use it to insert the company name into my query. So I can type "G_L" and it will auto-suggest "Select * from MyCompanyName$G_L Entry"
A free 14-day trial is available at http://www.red-gate.comRon0 -
SQL 2008 has auto-complete. It's one of the reasons I upgraded to sqk 2k8 on my laptop.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions