On our development server, we have a database server with collation: COLLATE SQL_Latin1_General_CP1_CI_AS.
After deploying our solution on a server and that database server has collation: COLLATE SQL_Latin1_General_CI_AS
That means if we have a query:
SELECT ('text' + 'abc') AS 'result'
I got this problem:
Implicit conversion of varchar value to varchar cannot be performed because the collation of the value is unresolved due to a collation conflict.
So I tried this: ALTER DATABASE [mydb] COLLATE SQL_Latin1_General_CP1_CI_AS
then I check the property of the myDB, the collate is changed to: SQL_Latin1_General_CI_CS_AS but I still get the same error.
Other topics suggest to reinstall the database. But that is not the case we will lose all of the data.
Any suggestion is very appreciated!
Thanks in advance.
In a nutshell, it's not enough to alter the database, as that only affects new objects that are created going forward. You also have to change all of the existing columns. This Microsoft support article should have all the details you'll need.
How to transfer a database from one collation to another collation in SQL Server
Related
I have a Golang program that may connect to databases with different character sets or collation.
For example the default at the time of writing of the Golang MYSQL driver is utf8mb4_general_ci https://github.com/go-sql-driver/mysql#collation
However if I connect to a database configured like so:
CREATE DATABASE example character set utf8mb4 collate utf8mb4_unicode_ci;
Can I expect "bad things to happen"? Indexes not to work?
In most case, there are no problem. For example, column collation is used regardless connection collation when WHERE column=? is used.
See also: https://dev.mysql.com/doc/refman/5.6/en/charset-collation-coercibility.html
But I can't speak it's 100% safe. It's safe to use one collation all place.
I am working with a Debian Server with xampp 1.8.3-2 and mysqlserver version 5.6.14 installed. In the old database, latin1_german2_ci was used as character collation for the database and the tables because of the german characters like ä,ö,ü,ß etc.. Now, I have to convert the collation of the tables into utf8_unicode_ci(collate of database is still in latin1_german2_ci). But after that, queries like this don't produce the correct answers anymore. i.e. it not only give everything with kö but with ko as well. How can I fix this?
SELECT * FROM users Where lastname like "%kö%"
edit: Just found one solution which uses COLLATE:
SELECT * FROM users Where lastname like "%kö%" COLLATE utf8mb4_german2_ci
However, this has to be adjusted depend which server connection collation is used, so if the server connection collation is utf8_unicode_ci, the query has to be changed into
SELECT * FROM users Where lastname like "%kö%" COLLATE utf8_german2_ci
So my question now: is there a better/more elegant way to solve my problem? Is there any option in the database to prevent this?
try to set the table's charset to UTF-8 and the collation to utf8_* and make sure there is no _ci and the end (_ci is for "case insensitive") otherwise MySQL will both perform case and accent-insensitive searches.
I'm trying to execute this statement on MYSQL.
SELECT * FROM mydatabase.mytable where LASTNAME COLLATE Latin1_General_CS_AI like '%DOODLEBOP%'
I keep getting this error:
Error Code: 1273. Unknown collation: 'Latin1_General_CS_AI'
Any ideas what I am missing or doing wrong? I'm also trying to essentially mimic an article I was reading online. Case Sensitive Searching
I tried a few quick Googles for the error and to no avail. Thanks
You are trying to use Microsoft SQL Server collation name on MySQL server.
For valid MySQL collation names and right syntax refer to MySQL documentation:
Character Sets and Collations in MySQL
Using COLLATE in SQL Statements
I think closest collation name for you query is: latin1_general_cs
This seems like I'm just missing something trivial, but I'm not able to change the collation of a table from Schema Default. Selecting anything from the dropdown just reverts to Schema Default.
I have utf8 - utf8_general_ci set as the schema collation, which I can change without issue.
However, even though the schema default is set to utf8_general_ci and the tables supposedly use the schema default, when I export the SQL CREATE script and import it in phpMyAdmin, the collation is set to latin1_swedish_ci.
The script itself contains a correct CREATE SCHEMA statement:
CREATE SCHEMA IF NOT EXISTS 'my_table' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
But the CREATE TABLE statements only include the engine assignment.
I'm using MySQL Workbench 6.0, and the server I'm using is running MySQL 5.5.34 and phpyMyAdmin 3.4.11.1. The server default collation is also utf8_general_ci.
EDIT: As I suspected, something stupid. I created the database via the cPanel beforehand rather than through the SQL script, and the default collation was set to latin1_swedish_ci.
However, that doesn't explain why I couldn't set specific collations on the tables in Workbench.
Collations when not given the way they're supposed to be given will certainly revert to Schema Default.
Where did you set the collation in MySQL Workbench actually? There are 2 places, one in modeling and one for live objects (existing db objects in a server).
If the latter, did you apply your changes?
How to set encoding of database in Microsoft Server Managment Studio?
I need to set utf8 to my database and I can't find option in settings of database.
You cannot set UTF8 encoding to SQL Server database.
You can use char/varchar data types to save characters- one character = one byte- but that also means you can save only limited characters (see collations).
You can use nchar/nvarchar data types to save characters- one character = two bytes (its UCS-2. for sorting, searching.. see collations).
Finally in varbinary column you can store UTF8 or whatever you need :).
It is taken from here How do I set database default Encoding?
Assuming by encoding you mean collation, you can change the default for new databases like:
alter database model collate SQL_Latin1_General_CP1_CI_AS
The change the collation of an existing database:
alter database YourDbName collate SQL_Latin1_General_CP1_CI_AS
The list of available collations is returned by a system function:
select * from fn_helpcollations()