Câu hỏi phỏng vấn MySQL
Câu hỏi

What are different integer data types in MySQL? How can you use unsigned integer in MySQL?

Câu trả lời

MySQL supports a variety of integer data types that cater to different ranges of numerical values. These integer types include:

  • TINYINT: A very small integer that uses 1 byte of storage. Its signed range is from -128 to 127, and its unsigned range is from 0 to 255[1][3].
  • SMALLINT: A small integer using 2 bytes of storage, with a signed range from -32768 to 32767 and an unsigned range from 0 to 65535[1][3].
  • MEDIUMINT: A medium-sized integer that occupies 3 bytes. Its signed range is from -8388608 to 8388607, and its unsigned range is from 0 to 16777215[1][3].
  • INT or INTEGER: A standard integer data type, using 4 bytes of storage. The signed range is from -2147483648 to 2147483647, and the unsigned range extends from 0 to 4294967295[1].
  • BIGINT: The largest integer data type in MySQL, requiring 8 bytes of storage. Its signed range is from -9223372036854775808 to 9223372036854775807, and the unsigned range is from 0 to 18446744073709551615[1][3].

The choice between these types depends on the range of values you expect to store in your database columns. For smaller ranges, using types like TINYINT can save storage space, while BIGINT is suitable for very large numbers.

Using Unsigned Integers in MySQL

In MySQL, integer types can be declared as UNSIGNED to only allow non-negative numbers. This effectively doubles the upper limit of the range for the data type, at the cost of excluding negative numbers. For example, an UNSIGNED INT can store values from 0 to 4294967295, whereas a signed INT's range is from -2147483648 to 2147483647[1].

To use an unsigned integer, you simply add the UNSIGNED keyword to the data type in y...

junior

junior

Gợi ý câu hỏi phỏng vấn

senior

What is advantage of FULLTEXT over LIKE for performing text search in MySQL?

middle

What is Stored Function in MySQL. How are they different from Stored Procedure?

middle

What is a trigger. What are different type of triggers in MySQL?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào