garbled text after SQL Server inserts Chinese data

Source: Internet
Author: User

In the course of doing the project today, I encountered a problem with the title, such as:

The database uses the SQL Server2012 version, and the script to create the table is as follows:

CREATE TABLE [dbo]. [Type]
(
[TypeId] INT not NULL PRIMARY KEY,
[TypeName] NVARCHAR (+) Not NULL,
[Description] NVARCHAR (255) Null
[CategoryId] INT not NULL DEFAULT 0
)

Depending on the solution mentioned in the relevant documentation, a field containing Chinese data is generally defined as the Nchar/nvarchar data type . However, in practice, even if the database table field is defined, it will produce garbled characters. At this point, another solution is attempted: When adding Chinese data, an uppercase n is added to the inserted middle character beforeThe script example is as follows:

MERGE dbo. [Type] As Target
USING (
SELECT 0, n' other ', n' undefined consumption category ', 0
UNION
SELECT 1, n' staple food ', n' m, noodles, oil, salt, etc. ', 1
UNION
SELECT 2, n' staple food ', n' meat, vegetables, eggs, deli, etc. ', 1
UNION
SELECT 3, n' dining ', n' with dine-in delivery ', 1
UNION
SELECT 4, N' drinks ', ', 2

It is verified that this scheme can solve Chinese garbled problem.

garbled text after SQL Server inserts Chinese data

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.