SQL Server inserts garbled language

Source: Internet
Author: User

If the collocation of the database is in English and the field is a varchar type, inserting Chinese data into the table will cause garbled characters.

Workaround:

Method 1. Modify the varchar to nvarchar type and add n before inserting the data, for example: INSERT INTO table_name (a) VALUES (N ' Chinese ')

Method 2. If you do not modify the field type or varchar, you need to modify the collocation of the database to Chinese, reference

---------------------------------------------------------------------------------------------------------

Also, when you are building a table, you specify the language of a field,

Method COLLATE Chinese_prc_cs_as_ws

Example:

CREATE TABLE Test
(
A varchar (255) COLLATE Chinese_prc_cs_as_ws NULL,
b varchar (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)

Test:

Insert test values (' Chinese ', ' Chinese ')

After inserting the field A is Chinese, B is??

---------------------------------------------------------------------------------------------------------

If you use a stored procedure to insert data, you need to change the corresponding parameter type to nvarchar.

Example:
Create PROCEDURE [dbo]. [Export_create]

@C_HM nvarchar (128)
As
INSERT into Export
([C_CCH])
Values
(@C_HM)

In the table, C_CCH is a varchar type.

SQL Server inserts garbled language

Related Article

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.