Data Types

89 important questions on Data Types

What is the notation for writing literal BIT values?

b'nnnn'

Can strings be non-binary and/or binary?

Both binary and non-binary

Can strings be case sensitive and/or case insensitive?

Both case sensitive and case insensitive
  • Higher grades + faster learning
  • Never study anything twice
  • 100% sure, 100% understanding
Discover Study Smart

What general type of data type is a BLOB field?

String datatype

Name a special temporal data type in MySQL?

The YEAR datatype

Does MySQL have support for spatial data types?

Yes

What 4 factors must be considered when choosing a numeric datatype?

1. The range of the values the data type represents
2. The amount of storage space required
3. The display width for presentation
4. The column precision for fixed-point and floating point values

What is precision and scale for floating-point and fixed-point values?

Precision is the number of significant digits (integer part) and scale is the number of digits to the right of the decimal (fractional part)

What are the 5 integer data types and their storage, signed, and unsigned range?

1. TINYINT         |  1 byte (256^1) |   -128 to 127    |     0 to 255
2. SMALLINT     |  2 bytes (256^2) |  -32,768 to 32,767     |      0 to 65,535
3. MEDIUMINT |  3 bytes (256^3)|  -8,388,608 to 8,388,608  | 0 to 16,777,215
4. INT          |  4 bytes (256^4)|  -(0.5*256^4) to 0.5*256^4-1 | 0 to 256^4 -1
5. BIGINT | 8 bytes

In the query century INT(4), what does the 4 stand for?

The display width of the column

What is the purpose of the display width?

To pad the output with spaces to the left (for presentation)

What is the default display width based on?

The number of characters needed to display the full range of values for the data type (including the minus sign)

What are the 2 floating point data types?

FLOAT (single precision, 4 bytes) and DOUBLE (double precision, 8 bytes)

What is the default precision and scale for the float and double datatype?

The maximum of the hardware of the host

In what format are floating-point values stored?

The mantissa/exponent representation

Why are floating point numbers approximates in MySQL?

Due to the mantissa/exponent representation for storage

Which data type is more accurate, FLOAT and DOUBLE or DECIMAL?

DECIMAL

What are the default precision and scale of a DECIMAL?

precision of 10 and a scale of 0

What is the storage requirement formula for a DECIMAL?

4 bytes per nine digits on each side of the decimal

What data type is the synonym of a DECIMAL in MySQL?

NUMERIC

What is the difference between a MySQL NUMERIC and a Standard SQL NUMERIC?

In standard SQL, the precision for NUMERIC must be exactly the number of digits given in the column definition. The precision for DECIMAL must be at least that many digits but is allowed to be more.

Given bit_col1 BIT(4) bit_col2 BIT(20), what does 4 and 20 stand for?

The amount of bits

What are the 8 string data types in MySQL, if they are variable or fixed length, and if they are binary or not?

1. CHAR | fixed | non-binary
2. VARCHAR | variable | non-binary
3. TEXT | variable | non-binary
4. BINARY | fixed | binary
5. VARBINARY | variable | binary
6. BLOB | variable | binary
7. ENUM | Enumeration of fixed set of legal values
8. SET | Set consisting of fixed set of legal values

What are the 5 factors to consider when choosing a string data type?

1. Is the string binary or non-binary?
2. Maximum length of values?
3. Fixed or variable amount of storage?
4. How are trailing spaces handled for comparison, storage and retrieval?
5. Number of distinct values required?

Do all character sets have the same storage requirements?

No, the amount of valid characters in the set defines the needed storage

Does a multi-byte character set require a fixed or variable number of bytes per character?

May be fixed or may be variable

What is the collation of a character set?

The sorting order

What are 2  factors the collation changes in character comparison?

Case sensitivity and accent sensitivity

Is a binary collocation case sensitive? and accent sensitive?

Both

Are comparisons for binary strings byte or character based?

Byte based

Can you write a byte value as quoted string in MySQL?

Yes

Is a multi-byte character if stored in a binary string treated as multiple individual bytes or a collection of bytes?

Multiple individual bytes

What is the range of acceptable values for the length of a VARCHAR?

0 to 65,635

How many bytes are used to store the length of a VARCHAR value?

1 byte for a value under 256, 2 bytes for a value above 256

What is the storage requirement of a CHAR(10) with a utf8 character set?

10 * the amount of bytes for the widest character (3), thus 10 * 3

What are the default character set and collation for columns?

The character set and collation of the table

What is the range of the length of a BINARY field?

0 to 255

Does MySQL remove trailing spaces for a BINARY field, and VARBINARY?

BINARY Yes
VARBINARY No

What are the four different sizes for a BLOB field? (From small to large)

TINYBLOB
BLOB
MEDIUMBLOB
LONGBLOB

What is the storage requirement formula for a TINYBLOB? And what is the maximum size of a TINYBLOB?

L + 1 byte and 255 bytes

As what datatype does MySQL internally store values of ENUM fields?

As integers

What is the maximum allowed amount of members for an ENUM field?

65,535

What is the storage formula for members of an ENUM field?

1 or 2 bytes
1 if <= 255
2 if >= 255

What happens with an invalid SET member on insertion?

It will be ignored

How does MySQL internally store values of a SET field?

As bitmap pattern

What is the maximum amount of SET members?

64

What is the difference between an integer 1 and string '1' in terms of SET or ENUM field values?

Integer is the numeric index and string is the string value

What 5 temporal datatypes are there in MySQL? (with storage requirement)

DATE 3 bytes
TIME 3 bytes
DATETIME 8 bytes
TIMESTAMP 4 bytes
YEAR 1 byte

What is the range of YEAR(4)?

1901 to 2155

What is the range of a TIME field?

-838:59:59 to 838:59:59

What is the range of a DATETIME field?

1000-01-01 00:00:00 to 9999-12-31 23:59:59

What is the range of a TIMESTAMP field?

1970-01-01 00:00:00 to mid-year 2037

What is the ZERO value for a DATETIME field?

0000-00-00 00:00:00

What is the default date representation of MySQL?

ANSI date representation also known as ISO 8601

What is the deviation between MySQL date input and ANSI SQL?

1. Leading zero's for months or days may be ommitted
2. The delimiter does not have to be a '-' character
3. Two digit years are converted to 4 digit years

What function formats dates? and times?

DATE_FORMAT() and TIME_FORMAT()

In what circumstances is a TIMESTAMP field appropriate?

When tracking creation and modification times

In what timezone are TIMESTAMP fields internally stored?

UTC

What does MySQL automatically assign on the first timestamp field?

DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP properties

Can one TIMESTAMP field have DEFAULT CURRENT_TIMESTAMP an another TIMESTAMP field ON UPDATE CURRENT_TIMESTAMP in the same table?

No

What is the meaning of a NULL insertion for TIMESTAMP fields?

CURRENT_TIMESTAMP

Is it possible to set the timezone for a MySQL connection?

Yes

What are the 3 time zone formats supported by MySQL?

1. signed hour/minute offset
2. named time zone
3. SYSTEM time zone

What is the default time zone for a connection?

The global timezone

What is the default of the global timezone in MySQL?

The SYSTEM timezone

How do you read and set the timezone for a connection?

Read: SELECT @@session.time_zone;
Write: SET time_zone = '+00:00'

What function supports TIMEZONE conversion?

CONVERT_TZ(date, from, to);

What are the 3 column attributes for numeric types? and what do they do?

1. UNSIGNED (No negative values)
2. ZEROFILL (left pad with zero's)
3. AUTO_INCREMENT (assign auto increment value)

What are the 3 column attributes for string types? and what do they do?

1. CHARACTER SET (sets the charset)
2. COLLATE (sets the collation)
3. BINARY (sets a binary collation)

What are the 2 general column attributes? What do they do?

1. NULL and NOT NULL (allow/disallow null values)
2. DEFAULT (set the default value)

What is the default default value for string fields?

Empty string

What is the default default value for date fields?

Zero value of the datatype

What datatypes do not support default values?

TEXT and BLOB (and numeric auto_increment)

What function returns the last inserted auto increment id?

LAST_INSERT_ID()

Does MySQL reassign the ids of deleted highest auto increment keys in a composite key?

Yes

Does MySQL allow an auto_increment field with a Non-unique index?

Yes

What happens when you INSERT a 0 in an auto_increment field?

Same as NULL, the next value except when NO_AUTO_VALUE_ON_ZERO is enabled then it's the value 0

What does MySQL by default do with erroneous input values?

It converts them to the nearest legal value

What happens on INSERT for a field with no default value and strict mode turned off?

The implicit default value is inserted and a warning is issued

What happens on INSERT for a field with no default value and strict mode is turned on in a non-transactional table?

Error occurs (partial update may exist)

What are the 5 conversions MySQL handles for invalid values?

1. Out-of-range to in-range values
2. String truncation
3. Conversion to datatype default
4. Enumeration and set value conversion
5. Handling of NULL to NOT NULL columns

What does MySQL insert when storing a value smaller than the minimum value of the datatype?

The minimum value of the datatype

What does MySQL do when a to lengthy string is inserted in a char field?

It truncates the string

What does MySQL insert for an invalid ENUM value?

An empty string

What does MySQL insert when inserting a NULL into a NOT NULL column in a multiple command statement?

The implicit default value for the column's datatype

Can partial updates occur when STRICT_ALL_TABLES turned on and invalid input data provided?

Yes

What 2 date restrictions are enabled in TRADITIONAL sql mode?

NO_ZERO_DATE and NO_ZERO_IN_DATE

How do you disable strict mode for a single insert/update statement?

INSERT IGNORE and UPDATE IGNORE

What sql mode enables support for invalid dates?

ALLOW_INVALID_DATES

The question on the page originate from the summary of the following study material:

  • A unique study and practice tool
  • Never study anything twice again
  • Get the grades you hope for
  • 100% sure, 100% understanding
Remember faster, study better. Scientifically proven.
Trustpilot Logo