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?
Related
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.
I'm new to SQL Server and today I began writing an SQL query. While writing SQL queries in SSMS (SQL Server Management Studio) for insert statements, I noticed that only table names were getting auto completed, but there is no option to auto complete the column name. Is there any way to autocomplete column names in a query?
INSERT INTO table_name (column1,column2,column3,...)
/* Here table name is auto completed. When i type a,a related tables were generated, but for columns there is no autocomplete. */
VALUES (value1,value2,value3,...);
Assuming you are using SQL Server Management Studio (SSMS), which most use people use when working with SQL Server, there is a weaker built in Intellisense that will fill in certain parts of SQL queries for you. If you want something stronger, you can check out third party addins. The most popular are probably SQL Prompt by Red Gate and SQL Complete by dbForge.
I have a table in Access 2007 with a field w/ data type = Number. In access, that field stores guids w/numbers and letters in them. When I right click the table and choose export, then I export it to SQL server -- the table shows up in SQL server w/guids w/ only numbers in them.
How can I preserve the GUIDs between Access and SQL server?
Instead of doing simple export to SQL, run SQL Server Upsize wizard from Database Tools menu:
This way Replication ID values will be preserved as GUIDs in SQL Server tables.
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
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('...');