Sunteți pe pagina 1din 5

DATE AND TIME DATA TYPES

DATE
The DATE data type is responsible for storing date information. Although MySQL displays DATE values
in a standard YYYY-MM-DD format, the values can be inserted using either numbers or strings. For
example, both 20100810 and 2010-08-10 would be accepted as valid input
DATETIME
The DATETIME data type is responsible for storing a combination of date and time information. Like
DATE, DATETIME values are stored in a standard format, YYYY-MM-DD HH:MM:SS; the values can
be inserted using either numbers or strings. For example, both 20100810153510 and 2010-08-10 15:35:10
would be accepted as valid input. The range of DATETIME is 1000-01-01 00:00:00 to 9999-12-31
23:59:59.
TIME
The TIME data type is responsible for storing time information and supports a range large enough not only
to represent both standard- and military-style time formats, but also to represent extended time intervals.
This range is –838:59:59 to 838:59:59.
TIMESTAMP [DEFAULT] [ON UPDATE]
The TIMESTAMP data type differs from DATETIME in that MySQL’s default behavior is to automatically
update it to the current date and time whenever an INSERT or UPDATE operation affecting it is executed.
TIMESTAMP values are displayed in HH:MM:SS format, and, like the DATE and DATETIME data types,
you can assign values using either numbers or strings. Itsstorage requirement is 4 bytes.
YEAR[(2|4)]
The YEAR data type is responsible for storing year-specific information, supporting numerous ranges
according to context:
• Two-digit number: 1 to 99. Values ranging between 1 and 69 are converted to values in the
range 2001 to 2069, while values ranging between 70 and 99 are converted to values in the
range 1970 to 1999.
• Four-digit number: 1901 to 2155.
• Two-digit string: "00" to "99." Values ranging between "00" and "69" are converted to values
in the range "2000" to "2069," while values ranging between "70" and "99" are converted to
values in the range "1970" to "1999."
• Four-digit string: "1901" to "2155."
NUMERIC DATA TYPES

1. BIGINT [(M)]
The BIGINT data type offers MySQL’s largest integer range, supporting a signed range of–
9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 and an unsigned range of 0 to
18,446,744,073,709,551,615.

2. INT [(M)] [UNSIGNED] [ZEROFILL]


The INT data type offers MySQL’s second-largest integer range, supporting a signed range of –
2,147,483,648 to 2,147,483,647 and an unsigned range of 0 to 4,294,967,295.

3. MEDIUMINT [(M)] [UNSIGNED] [ZEROFILL]


The MEDIUMINT data type offers MySQL’s third-largest integer range, supporting a signed
range of –8,388,608 to 8,388,607 and an unsigned range of 0 to 16,777,215.

4. SMALLINT [(M)] [UNSIGNED] [ZEROFILL]


The SMALLINT data type offers MySQL’s fourth-largest integer range, supporting a signed
range of –32,768 to 32,767 and an unsigned range of 0 to 65,535.

5. TINYINT [(M)] [UNSIGNED] [ZEROFILL]


The TINYINT data type is MySQL’s smallest integer range, supporting a signed range of
–128 to 127 and an unsigned range of 0 to 255.
6. DECIMAL([M[,D]]) [UNSIGNED] [ZEROFILL]
The DECIMAL data type is a floating-point number stored as a string, supporting a signed range
of –1.7976931348623157E+308 to –2.2250738585072014E–308 and an unsigned range of
2.2250738585072014E–308 to 1.7976931348623157E+308.
The DOUBLE data type is a double-precision floating-point number, supporting a signed range
of –1.7976931348623157E+308 to –2.2250738585072014E–308 and an unsigned range of
2.2250738585072014E–308 to 1.7976931348623157E+308.

7. FLOAT([M,D]) [UNSIGNED] [ZEROFILL]


This FLOAT data type variation is MySQL’s single-precision floating-point number
representation, supporting a signed range of –3.402823466E+38 to –1.175494351E–38 and an
unsigned range of 1.175494351E–38 to 3.402823466E+38.
8. FLOAT (precision) [UNSIGNED] [ZEROFILL]
This FLOAT data type variant is provided for ODBC compatibility. The degree of precision can
range between 1 to 24 for single precision and 25 to 53 for double precision. The range is the
same as that defined in the preceding FLOAT definition.

STRING DATA TYPES

[NATIONAL] CHAR(Length) [BINARY | ASCII | UNICODE]


The CHAR data type offers MySQL’s fixed-length string representation, supporting a
maximum length of 255 characters. If an inserted string does not occupy all of the Length spaces, the
remaining space will be padded by blank spaces. When retrieved, these blank
spaces are omitted.

[NATIONAL] VARCHAR(Length) [BINARY]


The VARCHAR data type is MySQL’s variable-length string representation, supporting a length of 0 to
65,535 characters as of version 5.0.3; 0 to 255 characters as of version 4.0.2; and 1 to 255 characters prior
to version 4.0.2.

LONGBLOB
The LONGBLOB data type is MySQL’s largest binary string representation, supporting a maximum length
of 4,294,967,295 characters.

LONGTEXT
The LONGTEXT data type is MySQL’s largest nonbinary string representation, supporting a maximum
length of 4,294,967,295 characters.

MEDIUMBLOB
The MEDIUMBLOB data type is MySQL’s second-largest binary string representation, supporting a
maximum of 16,777,215 characters.

MEDIUMTEXT
The MEDIUMTEXT data type is MySQL’s second-largest nonbinary text string, capable of storing a
maximum length of 16,777,215 characters.
BLOB
The BLOB data type is MySQL’s third-largest binary string representation, supporting a maximum length
of 65,535 characters.

TEXT
The TEXT data type is MySQL’s third-largest nonbinary string representation, supporting a maximum
length of 65,535 characters.

TINYBLOB
The TINYBLOB data type is MySQL’s smallest binary string representation, supporting a maximum length
of 255 characters.
TINYTEXT
The TINYTEXT data type is MySQL’s smallest nonbinary string representation, supporting a maximum
length of 255 characters.

ENUM(“member1”,“member2”,…“member65,535”)
The ENUM data type provides a means for storing a maximum of one member chosen from a predefined
group consisting of a maximum of 65,535 distinct members. The
choice of members is restricted to those declared in the column definition. If the column declaration
includes the NULL attribute, then NULL will be considered a valid value and will be the default. If NOT
NULL is declared, the first member of the list will be the default.

SET(“member1”, “member2”,…“member64”)
The SET data type provides a means for specifying zero or more values chosen from a predefined group
consisting of a maximum of 64 members.

DATA TYPE ATTRIBUTES

1. AUTO_INCREMENT
2. BINARY
The BINARY attribute is only used in conjunction with CHAR and VARCHAR values. When columns
are assigned this attribute, they will be sorted in case-sensitive fashion (in accordance with their ASCII
machine values). This is in contrast to the case-insensitive sorting when the BINARY attribute is
omitted. An example of a BINARY column assignment follows: hostname CHAR(25) BINARY NOT
NULL

3. DEFAULT
The DEFAULT attribute ensures that some constant value will be assigned when no other value is available.
This value must be a constant, because MySQL does not allow functional or expressional values to be
inserted. Furthermore, this attribute cannot be used in conjunction with BLOB or TEXT fields. If the NULL
attribute has been assigned to this field, the default value will be null if no default is specified. Otherwise
(specifically, if NOT NULL is an accompanying attribute), the default value will depend on the field data
type.An example of a DEFAULT attribute assignment follows: subscribed ENUM('No','Yes') NOT NULL
DEFAULT 'No'

4. INDEX
If all other factors are equal, the use of indexing is often the single most important step you can take toward
speeding up your database queries. Indexing a column creates a sorted array of keys for that column, each
of which points to its corresponding table row. Subsequently searching this ordered key array for the input
criteria results in vast increases in performance over searching the entire unindexed table because MySQL
will already have the sorted array at its disposal.

5. NATIONAL
The NATIONAL attribute is used only in conjunction with the CHAR and VARCHAR data types. When
specified, it ensures that the column uses the default character set, which MySQL already does by default.
In short, this attribute is offered as an aid in database compatibility.
6. NOT NULL
Defining a column as NOT NULL will disallow any attempt to insert a NULL value into the column. Using
the NOT NULL attribute where relevant is always suggested as it results in
at least baseline verification that all necessary values have been passed to the query.

7. NULL
The NULL attribute indicates that a column is allowed to have no value.

8. PRIMARY KEY
The PRIMARY KEY attribute is used to guarantee uniqueness for a given row. No values residing in a
column designated as a primary key are repeatable or nullable within that column.

9. UNIQUE
A column assigned the UNIQUE attribute will ensure that all values possess distinct values, except that
NULL values are repeatable. You typically designate a column as UNIQUE to
ensure that all fields within that column are distinct

S-ar putea să vă placă și