mysql equivalent data types

后端 未结 3 1361
忘掉有多难
忘掉有多难 2020-12-01 15:36

I\'m coming from a SQL Server background. What would the equivalent data types be for the following in MySQL:

NVARCHAR - provides support for internatio

3条回答
  •  猫巷女王i
    2020-12-01 16:26

    the equivalent is VARCHAR or TEXT

    MySql supports nchar and nvarchar but in a different way. This is implemented using character set and collation (which is a set of rules used for comparison of strings using the character set - such as whether the comparison should be case sensitive or not).

    MySql defines character set at 4 level:

    Server
    Database
    Table
    Column

    character set is inherited from the immediate top level if you do not specify one. What you need to do is to ensure that the column that you want to make of type nvarchar has "character set" set to any unicode character set (utf8 is the best choice I believe) either explicitly or by inheritance.

    For column level you can set "character set" as follows:

    create table nvarchar_test
    (
    _id varchar(10) character set utf8,
    _name varchar(200) character set ascii
    )
    

    In the above example _id will be able to take 10 unicode characters and _name will be able to take 100 unicode characters (each unicode character will evaluate to two ascii character)

    Please go through MySql reference for further explanation.

提交回复
热议问题