Tuesday, December 13, 2011

First real entry: MSSQL and Collation

Aside from the values inside the column, what else are affected?

All objects inside the database.  I just learned this few weeks ago when a problem was consulted to me.  I initially thought that values are affected and was surprised it is not the case.

So let's prove it; create a database - zCollationCI (case-insensitive) and zCollationCS (case-sensitive).
USE MASTER
GO

CREATE DATABASE [zCollationCI] ON NAME Sales_dat,
   
FILENAME 'D:\MSSQLDB\zCollationci.mdf',
   
SIZE 10,
   
MAXSIZE 50,
   
FILEGROWTH )LOG ONNAME 'Sales_log',
   
FILENAME 'D:\MSSQLDB\zCollationci_log.ldf',
   
SIZE 5MB,
   
MAXSIZE 25MB,
   
FILEGROWTH 5MB )COLLATE SQL_Latin1_General_CP1_CI_AS
GO

CREATE DATABASE [zCollationCS] ON NAME Sales_dat,
   
FILENAME 'D:\MSSQLDB\zCollationcs.mdf',
   
SIZE 10,
   
MAXSIZE 50,
   
FILEGROWTH )LOG ONNAME 'Sales_log',
   
FILENAME 'D:\MSSQLDB\zCollationcs_log.ldf',
   
SIZE 5MB,
   
MAXSIZE 25MB,
   
FILEGROWTH 5MB ) COLLATE SQL_Latin1_General_Cp1_CS_AS
GO
Create a table for each database and perform the two (2) "SELECT" statements.  You'll see the difference.
USE [zCollationCI]
CREATE TABLE [dbo].[testTable1](
   
[testCol01] [nchar](10) NULL,
   
[testCol02] [nchar](10)
)
-- lowercaseSELECT testcol01testcol02 FROM testtable1;-- following objects' case
SELECT 
testCol02testCol02 FROM testTable1;

USE
[zCollationCS]
CREATE TABLE [dbo].[testTable1](
   
[testCol01] [nchar](10) NULL,
   
[testCol02] [nchar](10)
)

-- lowercase
SELECT testcol01testcol02 FROM testtable1;
-- following objects' case
SELECT testCol02testCol02 FROM testTable1;
  
I also found similar this blog which gives another example.
I want some Moore - Blog about stuff and things and stuff. Mostly about SQL server and .Net 
Let me know if you find error(s) in my post, technical and grammatical so that i can correct it.  Please don't be harsh.  I'm n00b.

..