SQL Server 2008 Case Sensitivity problem - sql-server

My SQL Server query analyzer raises an error when I type my table names with lower-case letters.
My server and database collations are SQL_Latin1_General_CP1254_CI_AS.
Despite of it, Select * from table raises an error, while Select * From TABLE doesn't raise any error.
Where I am wrong? How can I make case-insensitive? I use SQL Server 2008

Give "select * from [table]" a try. And this is a silly question but is the name of the table, table?

Your server has a case insensitive collation, but each individual database may have its own collation. As it happens, this particular database has a case sensitive collation. If not explicitly specified (see CREATE DATABASE ... COLLATE ...) databases inherit the collation of the server they were originally created on. Likely this database was created on a server that had case sensitive collation and then attached/restored on your server.
the current database collation can be seen, for each database, in sys.databases:
select collation_name
from sys.databases
where database_id = db_id('...');

Related

Microsoft SQL Server case sensitive queries

Is it possibile to have databae-wide settings to make sql queries case-sensitive on Microsoft SQL Server, e.g. 2012?
I'm refering to http://vyaskn.tripod.com/case_sensitive_search_in_sql_server.htm and it turn out for me that I can only modify queries to handle collations per column or to modify schema for specific columns have case-sensitive collations.
If I try
"ALTER DATABASE my_database COLLATE SQL_Latin1_General_CP1_CS_AS;"
it is not helping. Instead I have a problem with column names in my queries. I'm wonderign if there are separate settings for column name and data case-sensitivity for Ms SQL Server?

SQL server collation change on the instance level

When a database is created from our application, it takes the default Collation. we don't want to pass the collation in the create database script.
A client has a collation set on the instance level that is Case Sensitive. So the database created for our application is in that collation which is something we don't want.
Can they change the collation on the instance level so the database that gets created will have the desired collation and they can change it back to whatever they want? How do we do this on the instance level?
Thanks for your time!
So the problem is that the database is not created by a script run in, say, SQL Management Studio, but a script launched from within the application.
As noted in the comments and another answers changing the server collation is possible but hairy, the best option in a case like this is creating the database empty, changing the collation (either with ALTER DATABASE or from Management Studio), and then create the rest of the database.
This would require changing the application, but only the creation of the database itself since the tables will take the collation of the database, not the server collation (and you can do it in a way that works for every client, check if the database exists and that case skip DB creation and proceed with the rest of objects).
As a final warning, note that having a DB with a collation different of the server collation would mean than the DB has a different collation than the tempdb, so if you use temporal tables you would have problems if you have WHERE's or JOIN's mixing temporal and regular tables. For example, supposing that SerialNumber is a char column, this query will fail with a collation error:
SELECT *
FROM Products
JOIN #TempTable ON #TempTable.SerialNumber=Products.SerialNumber
If that case you will have to modify the application and change the queries to something like this:
SELECT *
FROM Products
JOIN #TempTable ON #TempTable.SerialNumber=Products.SerialNumber COLLATE database_default
You can configure the instance collation which would require dropping the databases before changing it. Here is a link to setting or changing the Server Collation.
You can also do this on a database level. Here is information on setting or changing collation on the database level.
You may also want to read the collation clause which can also be applied to tables, columns, and casting expressions among additional options.

How to change Instance Collation of sql server running on amazon rds?

I'm running SQL Server 2008R2 Standard edition on and RDS instance. I need to change the server's collation.So how can i change?
Based on documentation:
Amazon RDS creates a default server collation for character sets when
a SQL Server DB instance is created. This default server collation is
currently English (United States), or more precisely,
SQL_Latin1_General_CP1_CI_AS.
You can change the default collation at the database, table, or column level by overriding the collation when creating a new database or database object. For example, you can change from the default collation SQL_Latin1_General_CP1_CI_AS to Japanese_CI_AS for Japanese collation support. Even arguments in a query can be type-cast to use a different collation if necessary.
So change to desired collation on
database
ALTER DATABASE db_name
COLLATE collate_name;
column
ALTER TABLE dbo.table_name ALTER COLUMN col_name
type COLLATE collate_name;

Is it possible to have a SQL Server database with case sensitive data only

Is it possible to have a SQL Server 2012 database with a collation that ensures only the data is treated as case sensitive, with the database objects still referenced in a case insensitive manner?
We are migrating the database used by an application to SQL Server, and this database contains case sensitive data. But we don't want the database objects to be treated in a case sensitive manner, as that will have a significant negative impact on the existing code.
All research tends to suggest that this isn't possible, and the best we can do is identify which columns really do need to be case sensitive, and set the collation for these accordingly so we can minimize the damage. Is this the best we can hope for?
#Cleggy, it looks like you already got the answer from #Xedni's comment, but adding it here as a reference for anyone reading this page in future.
SQL Server collation settings depend on the type of installation. Case sensitivity is subject to collation of the data.
By default, databases created with SQL Server inherit the server collation.
By default, column in tables created in a database inherit the database collation.
There are plenty of opportunities to choose a case sensitive collation for your data between these options:
By choosing one when you create the database (Or)
By choosing one when you design the table
Please follow this link for more on SQL Server Collations.
We can change the database collation to case sensitive using the following T-SQL.
ALTER DATABASE <Database_Name> COLLATE Latin1_General_CS_AS
The following T-SQL will be helpful in understanding the various case sensitivity options.
SELECT * FROM fn_helpcollations()

SQL Server 2005 : change collation for the existing database and LINQ2SQL

I have a SQL Server 2005 database. It was created with default collation which is not case-sensitive (my fault!). That's different from all other databases which I work with, where collations are by default case sensitive. I mostly consider comparing strings than sorting. I use Linq-to-SQL where there is no way to specify collation for WHERE clause.
It seems that changing collation of existing database / server (and all tables' fields!) is error-prone and there is no tools for this.
Maybe I'm missing something and there is a clean way?
try this:
Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=InstanceName
/SQLSYSADMINACCOUNTS=accounts /[ SAPWD= StrongPassword ]
/SQLCOLLATION=CollationName
Run this comman through SQL command promt and then rebuild the master database.
For specific DB
USE master;
GO
ALTER DATABASE yourDBname
COLLATE French_CI_AS ;
GO

Resources