How to make an SQL Server table read UTF8 text correctly

Asked

Viewed 26 times

-1

I have a query in which I need to do the column Name read UTF8 codes.

Here’s the code here:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO


CREATE TABLE [dbo].[MonsterList](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [Name] [varchar](32) NULL,
    [EffectID] [int] NOT NULL,
 CONSTRAINT [PK_MonsterList] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

I’ve tried to change the varchar for nvarchar, happens that this query pulls files . txt with names of "Monsters" is from a game.

However, when I translate these monsters using accentuation as for example: Dog, Action, etc..., the column Name or don’t pull the names, or when he pulls the code.

Is there a way I can leave this query reading UTF8 or ANSI codes correctly with accents?

1 answer

0

Good afternoon!

Your problem is the COLLATION in the table...

Testing with COLLATION Latin1_general_ci_as

inserir a descrição da imagem aqui

Upshot

inserir a descrição da imagem aqui

I changed the collation in create table, because once I do not explain the collation is the default database.

inserir a descrição da imagem aqui

So, you can perform the query by converting the char, varchar and/or nvarchar fields (strings), but depending on the case you will have performance losses!

This link can help you!

https://www.sqlshack.com/the-collate-sql-command-overview/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.