SlideShare une entreprise Scribd logo
1  sur  4
You can override the database collation for char, varchar, text, nchar, nvarchar, and ntext data
by specifying a different collation for a specific column of a table and using one of the following:



    •    The COLLATE clause of CREATE TABLE and ALTER TABLE. For example:




         Copy Code



         CREATE TABLE MyTable

            (PrimaryKey           int PRIMARY KEY,

              CharCol             varchar(10) COLLATE French_CI_AS NOT NULL

            )

         GO

         ALTER TABLE MyTable ALTER COLUMN CharCol

                           varchar(10)COLLATE Latin1_General_CI_AS NOT NULL

         GO


    •    SQL Server Management Studio. For more information, see Table Column Properties (SQL

         Server Management Studio).


    •    Using the Column.Collation property in SQL Server Management Objects (SMO).




You cannot change the collation of a column that is currently referenced by any one of the following:



    •    A computed column



    •    An index



    •    Distribution statistics, either generated automatically or by the CREATE STATISTICS

         statement
•   A CHECK constraint



      •   A FOREIGN KEY constraint




When you work with tempdb, the COLLATE clause includes a database_default option to specify that
a column in a temporary table uses the collation default of the current user database for the
connection instead of the collation of tempdb.


 Collations and text Columns
You can insert or update values in a text column whose collation is different from the code page of
the default collation of the database. SQL Server implicitly converts the values to the collation of the
column.


 Collations and tempdb
The tempdb database is built every time SQL Server is started and has the same default collation as
the model database. This is typically the same as the default collation of the instance. If you create a
user database and specify a different default collation than model, the user database has a different
default collation than tempdb. All temporary stored procedures or temporary tables are created and
stored in tempdb. This means that all implicit columns in temporary tables and all coercible-default
constants, variables, and parameters in temporary stored procedures have collations that are different
from comparable objects created in permanent tables and stored procedures.


This could lead to problems with a mismatch in collations between user-defined databases and system
database objects. For example, an instance of SQL Server uses the Latin1_General_CS_AS collation
and you execute the following statements:




Copy Code

CREATE DATABASE TestDB COLLATE Estonian_CS_AS;
USE TestDB;
CREATE TABLE TestPermTab (PrimaryKey int PRIMARY KEY, Col1 nchar );
In this system, the tempdb database uses the Latin1_General_CS_AS collation with code page 1252,
and   TestDB and TestPermTab.Col1 use the Estonian_CS_AS collation with code page
1257. For example:




Copy Code

USE TestDB;
GO
-- Create a temporary table with the same column declarations
-- as TestPermTab
CREATE TABLE #TestTempTab (PrimaryKey int PRIMARY KEY, Col1 nchar )
INSERT INTO #TestTempTab
SELECT * FROM TestPermTab
GO
With the previous example, the tempdb database uses the Latin1_General_CS_AS collation, and

TestDB and TestTab.Col1 use the Estonian_CS_AS collation. For example:


Copy Code

SELECT * FROM TestPermTab a INNER JOIN #TestTempTab on a.Col1 =
#TestTempTab.Col1
Because tempdb uses the default server collation and TestPermTab.Col1 uses a different
collation, SQL Server returns this error: "Cannot resolve collation conflict between
'Latin1_General_CI_AS_KS_WS' and 'Estonian_CS_AS' in equal to operation."


To prevent the error, you can use one of the following alternatives:



     •   Specify that the temporary table column use the default collation of the user database, not

         tempdb. This enables the temporary table to work with similarly formatted tables in multiple

         databases, if that is required of your system.




         Copy Code



         CREATE TABLE #TestTempTab

             (PrimaryKey int PRIMARY KEY,

               Col1 nchar COLLATE database_default

             )


     •   Specify the correct collation for the   #TestTempTab column:




         Copy Code
CREATE TABLE #TestTempTab

  (PrimaryKey int PRIMARY KEY,

   Col1 nchar COLLATE Estonian_CS_AS

  )

Contenu connexe

Tendances

Java class 8
Java class 8Java class 8
Java class 8
Edureka!
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - Thaipt
Framgia Vietnam
 
Microstrategy Intermediate Tables
Microstrategy Intermediate TablesMicrostrategy Intermediate Tables
Microstrategy Intermediate Tables
fozgu
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
paulguerin
 

Tendances (18)

Oracle SQL DML Statements
Oracle SQL DML StatementsOracle SQL DML Statements
Oracle SQL DML Statements
 
MS Sql Server: Creating Views
MS Sql Server: Creating ViewsMS Sql Server: Creating Views
MS Sql Server: Creating Views
 
Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL
 
Sql DML
Sql DMLSql DML
Sql DML
 
Java class 8
Java class 8Java class 8
Java class 8
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - Thaipt
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
PyCon DE 2013 - Table Partitioning with Django
PyCon DE 2013 - Table Partitioning with DjangoPyCon DE 2013 - Table Partitioning with Django
PyCon DE 2013 - Table Partitioning with Django
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
8. sql
8. sql8. sql
8. sql
 
TSQL in SQL Server 2012
TSQL in SQL Server 2012TSQL in SQL Server 2012
TSQL in SQL Server 2012
 
Microstrategy Intermediate Tables
Microstrategy Intermediate TablesMicrostrategy Intermediate Tables
Microstrategy Intermediate Tables
 
Versioning
VersioningVersioning
Versioning
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
 
Sql server-dba
Sql server-dbaSql server-dba
Sql server-dba
 
How to Fine-Tune Performance Using Amazon Redshift
How to Fine-Tune Performance Using Amazon RedshiftHow to Fine-Tune Performance Using Amazon Redshift
How to Fine-Tune Performance Using Amazon Redshift
 
1 ddl
1 ddl1 ddl
1 ddl
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 

En vedette

Koleksi Kuih Raya 2010 (Sazlan-0176809425)
Koleksi Kuih Raya 2010 (Sazlan-0176809425)Koleksi Kuih Raya 2010 (Sazlan-0176809425)
Koleksi Kuih Raya 2010 (Sazlan-0176809425)
PETRONAS
 
Male Gaze Analysis Megan Fox
Male  Gaze  Analysis   Megan  FoxMale  Gaze  Analysis   Megan  Fox
Male Gaze Analysis Megan Fox
BenSummerton
 

En vedette (6)

Koleksi Kuih Raya 2010 (Sazlan-0176809425)
Koleksi Kuih Raya 2010 (Sazlan-0176809425)Koleksi Kuih Raya 2010 (Sazlan-0176809425)
Koleksi Kuih Raya 2010 (Sazlan-0176809425)
 
SKT MIGAS
SKT MIGASSKT MIGAS
SKT MIGAS
 
Naruto 470
Naruto 470Naruto 470
Naruto 470
 
Call Searcher
Call SearcherCall Searcher
Call Searcher
 
Keepingitinperspective N
Keepingitinperspective NKeepingitinperspective N
Keepingitinperspective N
 
Male Gaze Analysis Megan Fox
Male  Gaze  Analysis   Megan  FoxMale  Gaze  Analysis   Megan  Fox
Male Gaze Analysis Megan Fox
 

Similaire à Setting And Changing The Column Collation.Doc

SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserver
lochaaaa
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6
Shahrzad Peyman
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
Alessandro Baratella
 

Similaire à Setting And Changing The Column Collation.Doc (20)

SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
SQL Database Performance Tuning for Developers
SQL Database Performance Tuning for DevelopersSQL Database Performance Tuning for Developers
SQL Database Performance Tuning for Developers
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserver
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
 
SQL Server Select Topics
SQL Server Select TopicsSQL Server Select Topics
SQL Server Select Topics
 
ADBMS Unit-II c
ADBMS Unit-II cADBMS Unit-II c
ADBMS Unit-II c
 
zekeLabs sql-slides
zekeLabs sql-slideszekeLabs sql-slides
zekeLabs sql-slides
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
MYSql manage db
MYSql manage dbMYSql manage db
MYSql manage db
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sq lite module6
Sq lite module6Sq lite module6
Sq lite module6
 
PL/SQL 3 DML
PL/SQL 3 DMLPL/SQL 3 DML
PL/SQL 3 DML
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Setting And Changing The Column Collation.Doc

  • 1. You can override the database collation for char, varchar, text, nchar, nvarchar, and ntext data by specifying a different collation for a specific column of a table and using one of the following: • The COLLATE clause of CREATE TABLE and ALTER TABLE. For example: Copy Code CREATE TABLE MyTable (PrimaryKey int PRIMARY KEY, CharCol varchar(10) COLLATE French_CI_AS NOT NULL ) GO ALTER TABLE MyTable ALTER COLUMN CharCol varchar(10)COLLATE Latin1_General_CI_AS NOT NULL GO • SQL Server Management Studio. For more information, see Table Column Properties (SQL Server Management Studio). • Using the Column.Collation property in SQL Server Management Objects (SMO). You cannot change the collation of a column that is currently referenced by any one of the following: • A computed column • An index • Distribution statistics, either generated automatically or by the CREATE STATISTICS statement
  • 2. A CHECK constraint • A FOREIGN KEY constraint When you work with tempdb, the COLLATE clause includes a database_default option to specify that a column in a temporary table uses the collation default of the current user database for the connection instead of the collation of tempdb. Collations and text Columns You can insert or update values in a text column whose collation is different from the code page of the default collation of the database. SQL Server implicitly converts the values to the collation of the column. Collations and tempdb The tempdb database is built every time SQL Server is started and has the same default collation as the model database. This is typically the same as the default collation of the instance. If you create a user database and specify a different default collation than model, the user database has a different default collation than tempdb. All temporary stored procedures or temporary tables are created and stored in tempdb. This means that all implicit columns in temporary tables and all coercible-default constants, variables, and parameters in temporary stored procedures have collations that are different from comparable objects created in permanent tables and stored procedures. This could lead to problems with a mismatch in collations between user-defined databases and system database objects. For example, an instance of SQL Server uses the Latin1_General_CS_AS collation and you execute the following statements: Copy Code CREATE DATABASE TestDB COLLATE Estonian_CS_AS; USE TestDB; CREATE TABLE TestPermTab (PrimaryKey int PRIMARY KEY, Col1 nchar ); In this system, the tempdb database uses the Latin1_General_CS_AS collation with code page 1252, and TestDB and TestPermTab.Col1 use the Estonian_CS_AS collation with code page 1257. For example: Copy Code USE TestDB; GO -- Create a temporary table with the same column declarations -- as TestPermTab CREATE TABLE #TestTempTab (PrimaryKey int PRIMARY KEY, Col1 nchar ) INSERT INTO #TestTempTab
  • 3. SELECT * FROM TestPermTab GO With the previous example, the tempdb database uses the Latin1_General_CS_AS collation, and TestDB and TestTab.Col1 use the Estonian_CS_AS collation. For example: Copy Code SELECT * FROM TestPermTab a INNER JOIN #TestTempTab on a.Col1 = #TestTempTab.Col1 Because tempdb uses the default server collation and TestPermTab.Col1 uses a different collation, SQL Server returns this error: "Cannot resolve collation conflict between 'Latin1_General_CI_AS_KS_WS' and 'Estonian_CS_AS' in equal to operation." To prevent the error, you can use one of the following alternatives: • Specify that the temporary table column use the default collation of the user database, not tempdb. This enables the temporary table to work with similarly formatted tables in multiple databases, if that is required of your system. Copy Code CREATE TABLE #TestTempTab (PrimaryKey int PRIMARY KEY, Col1 nchar COLLATE database_default ) • Specify the correct collation for the #TestTempTab column: Copy Code
  • 4. CREATE TABLE #TestTempTab (PrimaryKey int PRIMARY KEY, Col1 nchar COLLATE Estonian_CS_AS )