Skip to content

Commit 86cdb67

Browse files
authored
Update collation-and-unicode-support.md
1 parent b20a3b7 commit 86cdb67

1 file changed

Lines changed: 4 additions & 55 deletions

File tree

‎docs/relational-databases/collations/collation-and-unicode-support.md‎

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -624,67 +624,16 @@ For example, consider a column defined as **NVARCHAR(100)** that stores 180 byte
624624

625625
Therefore, it's required to know in advance what's the projected byte size for the column definition before converting existing data to UTF-8, and adjust the new data type size accordingly. Refer to the [!INCLUDE[tsql](../../includes/tsql-md.md)] script or the SQL Notebook in the [Data Samples GitHub](https://github.com/microsoft/sql-server-samples/blob/master/samples/features/unicode), which use the [DATALENGTH](../../t-sql/functions/datalength-transact-sql.md) function and the [COLLATE](../../t-sql/statements/collations.md) statement to determine the correct data length requirements for UTF-8 conversion operations in an existing database.
626626

627-
To change the server collation, allowing new databases to inherit the system collation by default, see [Set or Change the Server Collation](../../relational-databases/collations/set-or-change-the-server-collation.md).
627+
To change the column collation and data type in an existing table, use one of the methods described in [Set or Change the Column Collation](../../relational-databases/collations/set-or-change-the-column-collation.md).
628628

629-
To change the database collation, allowing new objects to inherit the database collation by default, see [Set or Change the Database Collation](../../relational-databases/collations/set-or-change-the-database-collation.md).
630-
631-
To change the column collation and data type in an existing table, use one of the methods described below. For more information, see [Set or Change the Column Collation](../../relational-databases/collations/set-or-change-the-column-collation.md).
632-
633-
#### Convert column data
634-
Consider one of the existing tables defined below:
635-
636-
```sql
637-
-- NVARCHAR column is encoded in UTF-16 because a supplementary character enabled collation is used
638-
CREATE TABLE dbo.MyTable (CharCol NVARCHAR(50) COLLATE Latin1_General_100_CI_AI_SC);
639-
640-
-- VARCHAR column is encoded the Latin code page and therefore is not Unicode capable
641-
CREATE TABLE dbo.MyTable (CharCol VARCHAR(50) COLLATE Latin1_General_100_CI_AI);
642-
```
643-
644-
To convert the column in-place to use UTF-8, run an `ALTER COLUMN` statement that sets the new data type and collation:
645-
646-
```sql
647-
ALTER TABLE dbo.MyTable
648-
ALTER COLUMN CharCol VARCHAR(50) COLLATE Latin1_General_100_CI_AI_SC_UTF8
649-
```
650-
651-
This method is easy to implement, however it's a possibly blocking operation which may become an issue for large tables and busy applications.
652-
653-
#### Copy and Replace
654-
Consider one of the existing tables defined below:
655-
656-
```sql
657-
-- NVARCHAR column is encoded in UTF-16 because a supplementary character enabled collation is used
658-
CREATE TABLE dbo.MyTable (CharCol NVARCHAR(50) COLLATE Latin1_General_100_CI_AI_SC);
659-
GO
660-
661-
-- VARCHAR column is encoded using the Latin code page and therefore is not Unicode capable
662-
CREATE TABLE dbo.MyTable (CharCol VARCHAR(50) COLLATE Latin1_General_100_CI_AI);
663-
GO
664-
```
665-
666-
To convert the column to use UTF-8, copy the data to a new table where the target column is already using UTF-8, and then replace the old table:
667-
668-
```sql
669-
CREATE TABLE dbo.MyTableNew (CharCol VARCHAR(50) COLLATE Latin1_General_100_CI_AI_SC_UTF8);
670-
GO
671-
INSERT INTO dbo.MyTableNew
672-
SELECT * FROM dbo.MyTable;
673-
GO
674-
DROP TABLE dbo.MyTable;
675-
GO
676-
EXEC sp_rename 'dbo.MyTableNew', 'dbo.MyTable’;
677-
GO
678-
```
679-
680-
This method is much faster than in-place conversion, but handling complex schemas with many dependencies (FKs, PKs, Triggers, DFs) and synching the tail of the table (if the database is in use) requires more planning.
629+
To change the database collation, allowing new objects to inherit the database collation by default, or to change the server collation, allowing new databases to inherit the system collation by default, see the [Related tasks](#Related_Tasks) section of this article.
681630

682631
## <a name="Related_Tasks"></a> Related tasks
683632

684633
|Task|Topic|
685634
|----------|-----------|
686-
|Describes how to set or change the collation of the instance of SQL Server|[Set or Change the Server Collation](../../relational-databases/collations/set-or-change-the-server-collation.md)|
687-
|Describes how to set or change the collation of a user database|[Set or Change the Database Collation](../../relational-databases/collations/set-or-change-the-database-collation.md)|
635+
|Describes how to set or change the collation of the instance of SQL Server. Note that changing the server collation does not change the collation of existing databases.|[Set or Change the Server Collation](../../relational-databases/collations/set-or-change-the-server-collation.md)|
636+
|Describes how to set or change the collation of a user database. Note that changing a database collation does not change the collation of existing table columns.|[Set or Change the Database Collation](../../relational-databases/collations/set-or-change-the-database-collation.md)|
688637
|Describes how to set or change the collation of a column in the database|[Set or Change the Column Collation](../../relational-databases/collations/set-or-change-the-column-collation.md)|
689638
|Describes how to return collation information at the server, database, or column level|[View Collation Information](../../relational-databases/collations/view-collation-information.md)|
690639
|Describes how to write Transact-SQL statements that are more portable from one language to another, or support multiple languages more easily|[Write International Transact-SQL Statements](../../relational-databases/collations/write-international-transact-sql-statements.md)|

0 commit comments

Comments
 (0)