Virtually everything you do in MySQL involves data in some way or another because the purpose of a database management system is, by definition, to manage data. Even a simple SELECT 1 statement involves expression evaluation to produce an integer data value. Every data value in MySQL has a type. For example, 37.4 is a number, and 'abc' is a string. Sometimes data types are explicit, as when you issue a CREATE TABLE statement that specifies the type for each column you declare as part of the table: CREATE TABLE mytbl ( int_col INT, /* integer-valued column */ str_col CHAR(20), /* string-valued column */ date_col DATE /* date-valued column */ ); Other times, data types are implicit, such as when you refer to literal values in an expression, pass values to a function, or use the value returned from a function: INSERT INTO mytbl (int_col,str_col,date_col) VALUES(14,CONCAT('a','b'),20020115); The INSERT statement shown here performs the following operations, all of which involve data types:
To use MySQL effectively, it's essential to understand how MySQL handles data. This chapter describes the types of data values that MySQL can handle and discusses the issues involved in working with those types:
Two appendixes provide additional information to supplement the discussion here about MySQL's column types, operators, and functions. These are Appendix B, "Column Type Reference," and Appendix C, "Operator and Function Reference." The examples used throughout this chapter use CREATE TABLE extensively. The statement should be reasonably familiar to you because we used it in the tutorial section of Chapter 1, "Getting Started with MySQL and SQL." See also the entry for CREATE TABLE in Appendix D, "SQL Syntax Reference." Several examples also use ALTER TABLE to modify the structure of tables. This statement too is discussed in the appendix as well as in Chapter 3, "MySQL SQL Syntax and Use." MySQL supports several table types, which differ in their properties. In some cases, the way you use a particular column type will be determined or influenced by the table type. This chapter refers to table types on occasion, but a more detailed description of the available types and their characteristics can be found in Chapter 3. |