How can insert Gujarati language in Microsoft SQL Server Management Studio?
I have tried to insert Gujarati and use nvarchar datatype but it's not working
The most common problem that I see when people aren't getting the outcome they want when inserting into an nvarchar column is that they aren't putting N in front of their string literal values (N is National Character Set).
If you have a table like this:
CREATE TABLE dbo.Test
(
TestID int IDENTITY(1,1) PRIMARY KEY,
TestValue nvarchar(100)
);
Here's a Chinese example that won't work (because of multi-byte string values):
INSERT dbo.Test (TestValue) VALUES ('Hello 你好');
With just single quotes, it's just an ASCII string. What would work is:
INSERT dbo.Test (TestValue) VALUES (N'Hello 你好');
I'm guessing your issue might be similar for Gujarati.
you can take column datatype Nvarchar and then you can insert in Gujarati
Related
Background: I'm doing some proofing of SQL Server 2019's _UTF8 collations (ref. https://learn.microsoft.com/en-us/sql/relational-databases/collations/collation-and-unicode-support?view=sql-server-ver15).
Use case: We sometimes have a need to store scientific names featuring Greek letters, such as DL-α-Tocopherol Acetate or Δ8-THC-Naphthoylester, etc.. Although this isn't common (most of our customers do not need this feature) but when the feature is needed, it almost non-negotiable. Since we normally don't need this feature we usually default the columns to varchar. I don't really want to get into a debate on nvarchar vs. varchar here, but suffice to say we only use nvarchar when needed, so when saving characters like α and Δ we'll change the data type and move on.
But the _UTF8 collations appear to allow these values to be saved in a varchar column without needing to change the data type to nvarchar:
UTF-8 support SQL Server 2019 (15.x) introduces full support for the
widely used UTF-8 character encoding as an import or export encoding,
and as database-level or column-level collation for string data. UTF-8
is allowed in the char and varchar data types, and it's enabled when
you create or change an object's collation to a collation that has a
UTF8 suffix. One example is changing LATIN1_GENERAL_100_CI_AS_SC to
LATIN1_GENERAL_100_CI_AS_SC_UTF8.
UTF-8 is available only to Windows collations that support
supplementary characters, as introduced in SQL Server 2012 (11.x). The
nchar and nvarchar data types allow UCS-2 or UTF-16 encoding only, and
they remain unchanged.
Azure SQL Database and Azure SQL Managed Instance also support UTF-8
on database and column level, while Managed Instance supports this on
a server level as well.
My problem:
I tried to save α and Δ with a simple example using SQL Server 2019 as follows:
CREATE TABLE dbo.SCI_DATA
(
id int NOT NULL,
name varchar(75) COLLATE Latin1_General_100_CI_AS_SC_UTF8
)
INSERT INTO dbo.SCI_DATA (id, name)
VALUES (1, 'DL-α-Tocopherol Acetate');
INSERT INTO dbo.SCI_DATA (id, name)
VALUES (2, 'Δ8-THC-Naphthoylester');
INSERT INTO dbo.SCI_DATA (id, name)
VALUES (3, 'Slainté');
SELECT *
FROM dbo.SCI_DATA;
DROP TABLE IF EXISTS dbo.SCI_DATA;
this returns
id name
---------------------------
1 DL-a-Tocopherol Acetate
2 ?8-THC-Naphthoylester
3 Slainté
The accented é is fine but Alpha α and Delta Δ are returned as ?. I'm wondering what I'm missing.
Even though the column is varchar with a UTF8 collation, it appears you still need to indicate that the data is Unicode with N'.
This modified example works:
CREATE TABLE dbo.SCI_DATA (
id int NOT NULL
, name varchar(75) COLLATE Latin1_General_100_CI_AS_SC_UTF8
)
INSERT INTO dbo.SCI_DATA (id, name) VALUES (1, N'DL-α-Tocopherol Acetate');
INSERT INTO dbo.SCI_DATA (id, name) VALUES (2, N'Δ8-THC-Naphthoylester');
INSERT INTO dbo.SCI_DATA (id, name) VALUES (3, 'Slainté');
SELECT * FROM dbo.SCI_DATA;
DROP TABLE IF EXISTS dbo.SCI_DATA;
Returns:
id name
1 DL-α-Tocopherol Acetate
2 Δ8-THC-Naphthoylester
3 Slainté
In SQL Server, I am trying to create a table that can store unicode characters. Specifically this one
https://www.fileformat.info/info/unicode/char/0144/index.htm
However if I pick nvarchar as the column type, then store it and then select it, it shows as a regular n.
How can I get it to store properly?
This works fine
DECLARE #t TABLE
(
InputChar NVARCHAR(10)
)
INSERT INTO #t (InputChar)
VALUES (N'ń')
INSERT INTO #t (InputChar)
VALUES ('ń')
SELECT * FROM #t
Are you making sure that when you inserting your strings you are specifying that the string is unicode ? e.g.N'yourstring'
I have a problem when trying with Like statement like this:
First I have the data sheet:
When I execute the Sql command it does not do what I want.
My syntax:
select * from tbUsers where nUserID like N'%p%';
It does not show any results. Although I know that 'Finds any values that have' p 'in any position'
result picture:
my code to create table:
Create table tbUsers(
iIDUser int identity(1,1) not null primary key,
nUserID nvarchar(50) null,
nPassWord nvarchar(50) null,
dDate datetime null,
nName nvarchar(50) null
)
INSERT INTO tbUsers(nUserID,nPassword,nName) VALUES('phuc','123456', 'Phuc Nguyen')
INSERT INTO tbUsers(nUserID,nPassword) VALUES('ngocanh','123456')
INSERT INTO tbUsers(nUserID,nPassword) VALUES('long','123456')
INSERT INTO tbUsers(nUserID,nPassword) VALUES('long%ngocanh','123456')
INSERT INTO tbUsers(nUserID,nPassword) VALUES('phuc nguyen','123456')
Please help me. Thank you.
Hi your problem can be your collation if you need the Vietnamese collation for any reason you can alter your query to use the collation in your query like this one:
select *
from tbUsers
where nUserID collate SQL_Latin1_General_CP1_CI_AS like N'%p%';
If not my recommendation is to re-create the database using the collation SQL_Latin1_General_CP1_CI_AS since this query will be slow.
Also take in consideration if you have an index in the user column using double %% this will not let your index to be used. If you use only one % the index will be activated. Take a look of the execution plan to review this.
If want to stay with the Vietnamese collation maybe change the collation to the columns you need for this type of functionality. This will help you with the performance.
To change the collation of a column use
ALTER TABLE MyTable ALTER COLUMN Column1 [TYPE] COLLATE [NewCollation]
You can take a look to this question for more details
How to set collation of a column with SQL?
Since you are using Vietnamese collation you are not getting back the rows. You can specify the collation in your query quite easily though and it will return the rows you are looking for.
select *
from tbUsers
where nUserID collate SQL_Latin1_General_CP1_CI_AS like N'%p%';
My SQL Server changes same characters in the Strings.
Example:
insert into TEST_TABLE
values ('árvíztűrő tükörfúrógép2');
inserts
árvízturo tükörfúrógép
The TEST_TABLE has only one column with type varchar(50).
How can I insert strings into a table in SQL Server?
You will most likely need an nvarchar (rather than varchar) data type on the column that allows unicode characters.
You will probably need to specify it being unicode too by prefixing the value with an "N".
insert into TEST_TABLE
values (N'árvíztűrő tükörfúrógép2');
Change the column datatype to nvarchar and try this:
insert into TEST_TABLE
values (N'árvíztűrő tükörfúrógép2');
Run the following code on your table:
ALTER TABLE TEST_TABLE ALTER COLUMN *ColumnName* nvarchar(50)
After that, it works like a charm (even without prefixing the inserting string with N).
I have a table that was imported from another source as a column with the char datatype, but the field has international characters. I would like to use nvarcvhar in my table. How can I achieve this?
I already tried updating the columns (using an alter table statement, or "cast as") but the info stored did not get converted.
Thanks
like this
ALTER TABLE TableName ALTER COLUMN ColumnName NVARCHAR(size)
example
CREATE TABLE test (bla VARCHAR(50))
GO
ALTER TABLE test ALTER COLUMN bla NVARCHAR(50)
Make sure that you prefix the string with N when doing the insert
INSERT test VALUES (N'漢語')
SELECT * FROM test
output
bla
--------------------------------------------------
漢語
(1 row(s) affected)
Whatever you do, don't use the SSMS designer/wizard, it will recreate the whole table, see here for example When changing column data types use ALTER TABLE TableName ALTER Column syntax, don't drop and recreate column
alter table your_table alter column your_column nvarchar(length)
SQLFiddle example
Your data is currently in EUC-CN, masquerading as CP1252. It is not lost.
You have several approaches available for conversion to Unicode (look at Converting SQL databases section for overview). In case of SQL Server, you can create extended stored procedures for conversion from EUC-CN to Unicode. This will work but it is not exactly easy (in this case use code page 51936 for your data).
With some luck, depending on what particular characters occur in your data, and what language packs you have installed, you might be able to convert as if from code page 936 like this:
ALTER DATABASE mydatabasename COLLATE Chinese_PRC
If this succeeds, do the same for every column you are going to convert:
ALTER TABLE mytablename ALTER COLUMN mycolumnname
varchar(4000) COLLATE Chinese_PRC NOT NULL
And only then convert them to NVARCHAR.