You are on page 1of 4

1. CREATE DATABASE employee; 2. SHOW DATABASES; 3.

USE EMPLOYEE; String Types: CHAR: Limit is 255 character - 8 bit character lengths CHAR fields store fixed-length values Trailing space are not preserved upon INSERT or SELECT 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 right-padded with spaces to the specified length

i.e 'Diamond' VARCHAR: Variable character Fields - 16 bit values VARCHAR fields preserve trailing spaces VARCHAR fields store data on a per-row basis independently Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used

Dean = 4 bytes Tricia = 6 bytes Diamond = 9 bytes 5. CREATE TABLE vc (v VARCHAR(4), c CHAR(4)); 6. INSERT INTO vc VALUES ('ab 7. SELECT * FROM vc; Values in CHAR and VARCHAR columns are sorted and compared according to the character set collation assigned to the column. All MySQL collations are of type PADSPACE. This means that all CHAR and VARCHAR values in MySQL are compared without regard to any trailing spaces. ', 'ab );

8. CREATE TABLE names (myname CHAR(10), yourname VARCHAR(10)); 9. INSERT INTO names VALUES ('Monty ', 'Monty ');

10. SELECT myname = 'Monty ', yourname = 'Monty ' FROM names; 11. ALTER TABLE nameS MODIFY myname char(255); 12. ALTER TABLE nameS MODIFY yourname varchar(65535); 13. ALTER TABLE nameS MODIFY myname char(256); 14. ALTER TABLE nameS MODIFY yourname char(65536);

BINARY and VARBINARY Types BINARY and VARBINARY types are similar to CHAR and VARCHAR, except that they contain binary strings rather than non-binary strings. That is, they contain byte strings rather than character strings. This means that they have no character set, and sort-ing and comparison are based on the numeric values of the bytes in the values. The permissible maximum length is the same for BINARY and VARBINARY as it is for CHAR and VARCHAR, except that the length for BINARY and VARBINARY is a length in bytes rather than in characters.

15. CREATE TABLE t (c BINARY(3)); 16. INSERT INTO t SET c = 'a';

BLOB and TEXT Types BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements. TINYTEXT - 1 byte (256 character) SMALLTEAT 2 Byte MEDIUMTEXT 3 Byte TEXT 4 Byte ENUM Type

An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column specification at table creation time. An enumeration value must be a quoted string literal; it may not be an expression, even one that evaluates to a string value. For example, you can create a table with an ENUM column like this: 15. CREATE TABLE sizes (name ENUM('small', 'medium', 'large') ); 16. INSERT INTO sizes( small ); If you insert an invalid value into an ENUM (that is, a string not present in the list of permitted values), the empty string is inserted instead as a special error value. This string can be distinguished from a normal empty string by the fact that this string has the numeric value 0. More about this later. If strict SQL mode is enabled, attempts to insert invalid ENUM values result in an error. 17. INSERT INTO sizes( xyz ); 18 INSERT INTO sizes( );

DATE: The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'. The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'; The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC. Illegal DATE, DATETIME, or TIMESTAMP values are converted to the zero value of the appropriate type ('0000-00-00' or '0000-00-00 00:00:00').

MySQL permits a relaxed format for values specified as strings, in which any punctuation character may be used as the delimiter between date parts or time parts. In some cases, this syntax can be deceiving. For example, a value such as'10:11:12' might look like a time value because of the : delimiter, but is interpreted as the year '2010-11-12' if used in a date context. The value '10:45:15' is converted to '0000-00-00' because '45' is not a legal month.

The server requires that month and day values be legal, and not merely in the range 1 to 12 and 1 to 31, respectively. With strict mode disabled, invalid dates such as '2004-04-31' are converted to '000000-00' and a warning is generated. With strict mode enabled, invalid dates generate an error.

MySQL does not accept TIMESTAMP values that include a zero in the day or month column or values that are not a valid date. The sole exception to this rule is the special zero value '0000-00-00 00:00:00'. Dates containing two-digit year values are ambiguous because the century is unknown. MySQL interprets two-digit year values using these rules: 1. Year values in the range 00-69 are converted to 2000-2069. 2. Year values in the range 70-99 are converted to 1970-1999.

You might also like