MSSQL Modify the collation of the database

Source: Internet
Author: User

1. Modify the collation of the database

ALTER DATABASE [CHARACTER] COLLATE chinese_prc_ci_as;


2. Modify the collation of the columns in the table
You cannot change the collation of a column if one of the following is currently referencing one.

    1. Computed columns
    2. Index
    3. Auto-generated or generated distribution statistics by the Create STATISTICS statement
    4. CHECK constraint
    5. FOREIGN KEY Constraint

--------------------------Modify the collation of a character column in a database table-----------------------------

1 DECLARE @S NVARCHAR( +)2 DECLARECCURSOR  for -- Case insensitive3     SELECT 'ALTER TABLE ['+B.name+'] ALTER COLUMN ['+A.name+'] '+Type_name (A.xtype)+4          Case  whenType_name (A.xtype)inch('TEXT','NTEXT') Then "' ELSE5             QUOTENAME(A.length,'(')6         END +'COLLATE chinese_prc_ci_as'7      fromsyscolumns A8         JOINSYSOBJECTS B ona.ID=b.ID andB.type='U'9     WHEREType_name (A.xtype)inch('VARCHAR','CHAR','NVARCHAR','NCHAR','TEXT','NTEXT')Ten OPENC One FETCHC into @S A  while @ @FETCH_STATUS=0 - BEGIN -     EXEC(@S) the     FETCHC into @S - END - CLOSEC - deallocateC + GO

MSSQL Modify the collation of the database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.