November 13, 2003 at 3:37 pm
Is there a way to create a database that is case sensitive? Books online shows how to create an instance that is case sensitive but I'd simply like to create a db that is case sensitive.
November 13, 2003 at 3:58 pm
You can set the default collation of a database when you create it.
--Jonathan
--Jonathan
November 13, 2003 at 4:06 pm
I see that in BOL now....thanks
November 14, 2003 at 7:41 am
To expand on this issue I was hoping to read more specifics, and followed up on this myself:
If I was creating a new database, what collation would I use to make it case sensitive?
use this statement from the BOL to see what collations are available:
SELECT *
FROM ::fn_helpcollations()
In my db there are 753 collations returned by this statement.
most of them are for foreign languages, but which one would I use?
To answer my own question but leave it for others to read,
my current databases are SQL_Latin1_General_CP1_CI_AS.
I found this out by choosing a table with a varchar field, and using EM to script the database. the collation is part of the definition for the varchar field.
The closest match for a case-sensitive version of that collation is from the function above:
SQL_Latin1_General_CP1_CS_AS Latin1-General, case-sensitive, accent-sensitive, kanatype-insensitive, width-insensitive for Unicode Data, SQL Server Sort Order 51 on Code Page 1252 for non-Unicode Data.
and lastly, to create a simple database with that collation as it's default:
CREATE DATABASE mytest
collate SQL_Latin1_General_CP1_CS_AS
From there, you'd want to add a table with a varchar field,and do test selects where name='BOB' vs name='Bob' or something similar
Also note that tablenames and field names are case sensitive in this situation as well;
These statements work just fine, and create two tables with similar names:
create table Whatever(TESTNAME varchar(20),TestName varchar(20))
create table whatever(TESTNAME varchar(20),TestName varchar(20))
Edited by - Lowell on 11/14/2003 07:49:50 AM
Lowell
November 14, 2003 at 9:16 am
If case sensitivity is required and the collation of the db or column is not case sensitive, a cast can be used to change it without db redesign. Changing the collation in an existing db is risky - every query would be at risk of behaving differently. A work around in an order by, for example,
select top 100 last_name
from employees
where last_name like 's%'
order by (cast(last_name as varchar(50)) COLLATE Latin1_General_BIN)
I also tried the SQL_Latin1_General_CP1_CS_AS collation in the order by. It worked on one server and did not on another - I did not have time investigate why. However, even when the order by did not work in a case sensitive fashion using SQL_Latin1_General_CP1_CS_AS, the compares did. Can anybody explain this for me?
RandyHelpdesk: Perhaps Im not the only one that does not know what you are doing. 😉
November 14, 2003 at 9:36 am
quote:
If case sensitivity is required and the collation of the db or column is not case sensitive, a cast can be used to change it without db redesign. Changing the collation in an existing db is risky - every query would be at risk of behaving differently. A work around in an order by, for example,select top 100 last_name
from employees
where last_name like 's%'
order by (cast(last_name as varchar(50)) COLLATE Latin1_General_BIN)
I also tried the SQL_Latin1_General_CP1_CS_AS collation in the order by. It worked on one server and did not on another - I did not have time investigate why. However, even when the order by did not work in a case sensitive fashion using SQL_Latin1_General_CP1_CS_AS, the compares did. Can anybody explain this for me?
OP's question referred to creating, not changing a database.
I just cast to varbinary when I need case sensitivity with case-insensitive data.
--Jonathan
--Jonathan
November 17, 2003 at 2:09 pm
We use Latin1_General_BIN. Watch out if you use temp tables in stored procedure are your system tables (tempdb) have a different collation sequence.
November 20, 2003 at 2:09 pm
I use Latin1_General_BIN as well. As robinhc says, watch anything that uses the tempdb if the database collation is different to the server collation.
Also naming standards help a lot, as object names are case sensitive as well.
Steven
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply