DDL Statement in MYSQL
DDL Statement in MYSQL
Example:
mysql>CREATEDATABASEdemo;
Example:
mysql>USEdemo;OR mysql>CONNECTdemo;
How to create a Table by copying the structure and data of an existing Table?
mysql>CREATETABLEstudentASSELECT*FROMemployees;
SMALLINT: A small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535.
MEDIUMINT: A medium-sized integer. The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215.
INT: A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.
BIGINT:
large
integer.
The
signed
range
is
-9223372036854775808
to
FLOAT: A small (single-precision) floating-point number. Permissible values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38. These are the theoretical limits, based on the IEEE standard. The actual range might be slightly smaller depending on your hardware or operating system.
DATE: A date. The supported range is '1000-01-01' to '9999-12-31'. MySQL displays DATE values in 'YYYY-MM-DD' format.
TIME : A time. The range is '-838:59:59' to '838:59:59'. MySQL displays TIME values in 'HH:MM:SS' format.
DATETIME: A date and time combination. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. MySQL displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format.
YEAR[(2|4)]: A year in two-digit or four-digit format. The default is four-digit format. In four-digit format, the permissible values are 1901 to 2155, and 0000. In two-digit format, the permissible values are 70 to 69, representing years from 1970 to 2069. MySQL displays YEAR values in YYYY format.
TIMESTAMP: A timestamp. The range is '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
The CHAR and VARCHAR Types: The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters. The length of a CHAR column is fixed to the length that you declare when you create the
table. The length can be any value from 0 to 255. When CHAR values are stored, they are rightpadded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed. Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.