I want some Moore

Blog about stuff and things and stuff...
mostly about SQL server and .Net
posts - 158, comments - 1438, trackbacks - 33

My Links

SQLTeam.com Links

News

Hi! My name is 
Mladen Prajdić  I'm from Slovenia and I'm currently working as a .Net (C#) and SQL Server developer. I'm also a MCP and MCTS for SQL Server. 
Welcome to my blog.

Search this Blog
 

My Blog Feed via Email


Get your Google PageRank
Users Online: who's online

Article Categories

Archives

Post Categories

Cool software

Other Blogs

Other stuff

SQL stuff

When are SQL Server schema objects Case Senstive?

I've come across an interesting thing today that i didn't even think could be an issue:

Case senstive object names (tables, columns, triggers, views, etc....).

If your database is created with a Case Sensitive collation then all object names will be Case Sensitive.

I always thought that collations are used for data and not schema but i guess i was wrong.

We had an issue with a view that had a lower case column name in it when it should be uppercase.

 

A bit of code to prove it:

create database testCollation collate Latin1_General_CS_AS -- case sensitive collation
go
use testCollation 

create table Test(Col1 int, col2 int)
insert into Test
select 1, 1 union all
select 1, 2 union all
select 2, 1 union all
select 2, 2 
go
SELECT Col1, col2 FROM Test -- works
SELECT col1, col2 FROM Test -- fails with error: Invalid column name 'col1'.
SELECT Col1, col2 FROM test -- fails with error: Invalid object name 'test'.

drop table Test
use master
drop database testCollation 

Print | posted on Thursday, December 07, 2006 2:05 PM

Feedback

# re: When are SQL Server schema objects Case Senstive?

The schema itself is also stored in database tables. Because the collation affects all tables in the database the schema is affected by this setting, too.

I have experienced this in my latest project. It is very annoying at the beginning (you're used to use case-insensitive SQL), but after a while you get used to it ;)
12/7/2006 3:32 PM | Gerald

# re: When are SQL Server schema objects Case Senstive?

yes exactly.

but somehow i managed to ignore that :))
12/7/2006 4:06 PM | mladen

# re: When are SQL Server schema objects Case Senstive?

Not sure why you see this as surprising?
Enlighten me:-p
12/8/2006 3:02 AM | Jon

# re: When are SQL Server schema objects Case Senstive?

I'm not seeing it as surprising...
It's interesting and shows how a simple collation can give you some trouble.

and if you start working on a new server you know nothing about and you get this
type of error i'm betting you're not going to think of collations first.
12/8/2006 12:35 PM | Mladen

# re: When are SQL Server schema objects Case Senstive?

Well I do agree some people will have problems, but if you come from a programming background its not so bad. C/C++ is case sensitive as well so
int i;
int I;

are two different things. So its not so bad!
12/8/2006 2:18 PM | Jon

# re: When are SQL Server schema objects Case Senstive?

I come from a C/C++ world so when I first came across t-sql, I was surprised and somewhat disappointed that it is NOT case sensitive by default (at least, most databases I have worked with have been case-insensitive)
12/14/2006 3:40 AM | Jesse

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 3 and 5 and type the answer here:

Powered by: