Difference between varchar and nvarchar in MySQL [duplicate] - mysql

This question already has an answer here:
What is the difference between varchar and nvarchar with the same character set and collation in mysql
(1 answer)
Closed 2 days ago.
Please ecplain the usuability difference between varchar and nvarchar in MYSQL
In which case, we should use varchar datatype column and nvarchar datatype column using MySQL

Nvarchar and Varchar both are used to store variable length character data type.
But Nvarchar stores unicode characters like chinese,japanese.
Nvarchar length is two times its actual length.

Related

mysql jdbc: what is column size for BIGINT? [duplicate]

This question already has answers here:
Types in MySQL: BigInt(20) vs Int(20)
(6 answers)
Closed 5 years ago.
mysql jdbc: what is column size for BIGINT?
jdbc:
id BIGINT(20)
ResultSet columns = databaseMetaData.getColumns("foo", "bar", "table", "id");
columns.next();
int columnSize = columns.getInt(7);
the columnSize is 19. Is it 19 bytes?
Q: What is column size for BIGINT?
The MySQL BIGINT datatype is a 64-byte signed integer. From a JDBC resultset, that can be handled in Java as a long.
With the unsigned variant, the MySQL BIGINT UNSIGNED dataype, that could be handled as java.math.BigInteger. (The maximum value of MySQL BIGINT UNSIGNED exceeds the maximum value of Java long.)
Q: Is it 19 bytes?
The longest string value that MySQL will return for a BIGINT would be 20 characters. The lowest possible value for a MySQL BIGINT, represented as a character string is '-9223372036854775808'. (That's 19 digits, but an extra character is required for the minus sign.)
The largest value of BIGINT would have a string representation of 19 characters.
For the unsigned variant BIGINT UNSIGNED the largest value would be represented as 20 decimal digits, thus 20 characters.
In terms of storage in the MySQL database, the BIGINT datatype requires eight bytes.

INT Datatype in MySQL

Does the INT, TINYINT, MEDIUMINT, BIGINT in MySQL Accepts the character '-' ? I used the data type INT in a column and the data inside has the character '-'. And somehow it didn't accept it. If it's not possible for INT data types, should I use VARCHAR?
The values for an integer in SQL are:
-2147483648 through 2147483647
And the byte size is 4 bytes.
Other maximum values:
BigInt: -9223372036854775808 through 9223372036854775807 (8 bytes)
SmallInt: -32768 through 32767 (2 bytes)
TinyInt: 0 through 255 (1 byte)
it dosent accept any char or string values like "-"
use varchar datatype if u want to insert "-"
Use VARCHAR(45) or TEXT datatype, if you want to insert characters.
you have to use Varchar DataType for this.
It will support both Int and Special Symbol like '-'
If you are not going to do any arithmetic operaion means then you can
use Varchar or text DataType

How to convert MYSQL UTF-8 when a row size is too large?

I'm on a MYSQL database attempting to alter my table encoded in latin1 to UTF-8. The tables name is Journalist that has 12 columns listed as varchar with max length of 3000. This is the sql i'm running.
ALTER TABLE `journalist` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
The error I'm receiving
Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
Do I have to alter the size of the table before I run this conversion query?
and/or how I might accomplish this encoding alteration otherwise?
I did what #Wrikken suggested. I deleted my table and lowered varchar's max_length attributes to 1500 from 3000. I then ran this SQL on my new empty table
ALTER TABLE `table_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
from here, I repopulated it with my backup table, using a script.
To answer the question:
Lower varchar max_length limits
Or change varchar fields to LONGTEXT, or BLOBS

What is the purpose of the column length in TINYINT(M)? [duplicate]

This question already has answers here:
Types in MySQL: BigInt(20) vs Int(20)
(6 answers)
Closed 9 years ago.
I studied the MySQL documentation and am now unsure what the column length specification (M) in TINYINT(M) means. A TINYINT UNSIGNED has a value range of 0 to 255, but TINYINT(1) UNSIGNED has a range of 0 to 9 ?
Is it better for compression?
From MySQL documentation about numeric type attributes:
The display width does not constrain the range of values that can be
stored in the column. Nor does it prevent values wider than the column
display width from being displayed correctly. For example, a column
specified as SMALLINT(3) has the usual SMALLINT range of -32768 to
32767, and values outside the range permitted by three digits are
displayed in full using more than three digits.
When used in conjunction with the optional (nonstandard) attribute
ZEROFILL, the default padding of spaces is replaced with zeros. For
example, for a column declared as INT(4) ZEROFILL, a value of 5 is
retrieved as 0005.
That said, you should consider this attribute only if you care about the 0s you could show on the left or if you are in a CLI environment.
Furthermore, if you declare a field as tinyint(2) and the number stored in is 113, all 3 characters will shown (despite what previous answer said)

Why MYSQL Desc command showing char instead of nchar?

I have created two columns in a tables with NATIONAL VARCHAR Data Type? But, when i am running the command,
desc
The result shows the datatype as varchar, not nvarchar. Why is it so? Am i doing some thing wrong?
PENAME NATIONAL VARCHAR(255),
PNAME NATIONAL VARCHAR(255) NOT NULL,
MySQL does not have separation of nvarchar and varchar (like SQL Server).
Instead, you define the CHARACTER SET (aka CHARSET) to describe the data (ansi, utf8 etc) therein. This is orthoganal to collation in MySQL (collation defines how the data is sorted and compared)
NATIONAL VARCHAR (n) is just a synonym for VARCHAR (n) CHARACTER SET utf8