Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a column case sensitive in sql 2005 or 2008

Is it possible to change the default collation based on a column? i want to make 1 column case sensitive but all the others not

like image 701
MichaelD Avatar asked Apr 30 '09 06:04

MichaelD


People also ask

How do I make a column case sensitive in SQL?

You can also make column case sensitive by changing column's collation from case insensitive SQL_Latin1_General_CP1_CI_AI to case sensitive Latin1_General_CS_AS. Lets use Alter Command to change the column Name collation from case insensitive to case sensitive.

Is SQL case sensitive for column names?

The SQL keywords are case insensitive ( SELECT , FROM , WHERE , etc), but they are often written in all caps. However, in some setups, table and column names are case sensitive. MySQL has a configuration option to enable/disable it.

Are columns case sensitive?

Column, index, stored routine, and event names are not case-sensitive on any platform, nor are column aliases. However, names of logfile groups are case-sensitive. This differs from standard SQL.

Where is SQL case sensitive?

The SQL keywords (SELECT, FROM, WHERE, etc.) are case-insensitive, yet they are frequently expressed in all capitals. Table and column names are case-sensitive in some settings. MySQL provides a setting that allows you to enable or disable it.


2 Answers

ALTER TABLE ALTER COLUMN allows to change collation for a single column:

alter table Foo alter column Bar ntext collate Latin1_General_CS_AS 

(collation might be incorrect)

like image 59
Anton Gogolev Avatar answered Sep 26 '22 06:09

Anton Gogolev


I don't specifically know SQL Server, but the generally accepted DBMS practice (for compatibility) would be to either:

  • put insert and update triggers on the table so that they're stored in the case you want.
  • use generated columns to store another copy of the column in the case you want.

There may be a faster way to do it in SQL Server but you should be careful of solutions that push workload into the SELECT statements - they never scale well. It's almost always better doing this as part of inserts and updates since that's the only time data changes - doing it that way minimizes the extra workload.

like image 35
paxdiablo Avatar answered Sep 25 '22 06:09

paxdiablo