Note that if you are using @strong{MySQL} 3.22 (or earlier) or if you
are trying to follow ANSI SQL, you can't use expressions in @code{GROUP
Note that if you are using @strong{MySQL} Version 3.22 (or earlier) or if
you are trying to follow ANSI SQL, you can't use expressions in @code{GROUP
BY} or @code{ORDER BY} clauses. You can work around this limitation by
using an alias for the expression:
...
...
@@ -16901,7 +16938,7 @@ mysql> SELECT id,FLOOR(value/100) AS val FROM tbl_name
GROUP BY id,val ORDER BY val;
@end example
In @strong{MySQL} 3.23 you can do:
In @strong{MySQL} Version 3.23 you can do:
@example
mysql> SELECT id,FLOOR(value/100) FROM tbl_name ORDER BY RAND();
...
...
@@ -16909,7 +16946,7 @@ mysql> SELECT id,FLOOR(value/100) FROM tbl_name ORDER BY RAND();
@findex CREATE DATABASE
@node CREATE DATABASE, DROP DATABASE, Functions, Reference
@section @code{CREATE DATABASE} syntax
@section @code{CREATE DATABASE} Syntax
@example
CREATE DATABASE [IF NOT EXISTS] db_name
...
...
@@ -16930,7 +16967,7 @@ You can also create databases with @code{mysqladmin}.
@findex DROP DATABASE
@node DROP DATABASE, CREATE TABLE, CREATE DATABASE, Reference
@section @code{DROP DATABASE} syntax
@section @code{DROP DATABASE} Syntax
@example
DROP DATABASE [IF EXISTS] db_name
...
...
@@ -16942,7 +16979,7 @@ database. @strong{Be VERY careful with this command!}
@code{DROP DATABASE} returns the number of files that were removed from
the database directory. Normally, this is three times the number of
tables, because normally each table corresponds to a @file{.MYD} file, a
@file{.MYI} file and a @file{.frm} file.
@file{.MYI} file, and a @file{.frm} file.
The @code{DROP DATABASE} command removes from the given database
directory all files with the following extensions:
...
...
@@ -16953,19 +16990,19 @@ directory all files with the following extensions:
@item .MYI @tab .db @tab .frm
@end multitable
All subdirectories that consists of 2 digits (@code{RAID} directories)
All subdirectories that consists of 2 digits (@code{RAID} directories)
are also removed.
In @strong{MySQL} 3.22 or later, you can use the keywords @code{IF EXISTS} to
prevent an error from occurring if the database doesn't exist.
In @strong{MySQL} Version 3.22 or later, you can use the keywords
@code{IF EXISTS} to prevent an error from occurring if the database doesn't
exist.
@cindex @code{mysqladmin}
You can also drop databases with @code{mysqladmin}.
@xref{Programs}.
You can also drop databases with @code{mysqladmin}. @xref{Programs}.
@findex CREATE TABLE
@node CREATE TABLE, ALTER TABLE, DROP DATABASE, Reference
@section @code{CREATE TABLE} syntax
@section @code{CREATE TABLE} Syntax
@menu
* Silent column changes:: Silent column changes
...
...
@@ -17052,20 +17089,21 @@ creates a table with the given name in the current database. Rules for
allowable table names are given in @ref{Legal names}. An error occurs if
there is no current database or if the table already exists.
In @strong{MySQL} 3.22 or later, the table name can be specified as
In @strong{MySQL} Version 3.22 or later, the table name can be specified as
@code{db_name.tbl_name}. This works whether or not there is a current
database.
In @strong{MySQL} 3.23, you can use the @code{TEMPORARY} keyword when you
create a table. A temporary table will automatically be deleted if a
In @strong{MySQL} Version 3.23, you can use the @code{TEMPORARY} keyword when
you create a table. A temporary table will automatically be deleted if a
connection dies and the name is per connection. This means that two different
connections can both use the same temporary table name without conflicting
with each other or with an existing table of the same name. (The existing table
is hidden until the temporary table is deleted).
In @strong{MySQL} 3.23 or later, you can use the keywords @code{IF NOT EXISTS}
so that an error does not occur if the table already exists. Note that there
is no verification that the table structures are identical.
In @strong{MySQL} Version 3.23 or later, you can use the keywords
@code{IF NOT EXISTS} so that an error does not occur if the table already
exists. Note that there is no verification that the table structures are
identical.
Each table @code{tbl_name} is represented by some files in the database
directory. In the case of MyISAM-type tables you will get:
...
...
@@ -17078,7 +17116,7 @@ directory. In the case of MyISAM-type tables you will get:
@end multitable
For more information on the properties of the various column types, see
@ref{Column types}.
@ref{Column types}:
@itemize @bullet
@item
...
...
@@ -17099,13 +17137,13 @@ table but not with a @code{MyISAM} table. If you delete all rows in the
table with @code{DELETE FROM table_name} (without a @code{WHERE}) in
@code{AUTOCOMMIT} mode, the sequence starts over for both table types.
@strong{Note:} There can be only one @code{AUTO_INCREMENT} column per
table, and it must be indexed. @strong{MySQL} 3.23 will also only work
properly if the auto_increment column only has positive
@strong{NOTE:} There can be only one @code{AUTO_INCREMENT} column per
table, and it must be indexed. @strong{MySQL} Version 3.23 will also only
work properly if the auto_increment column only has positive
values. Inserting a negative number is regarded as inserting a very large
positive number. This is done to avoid precision problems when
numbers 'wrap' over from positive to negative and also to ensure that one
doesn't accidently get a auto_increment column that contains 0.
doesn't accidently get an auto_increment column that contains 0.
@cindex ODBC compatibility
@cindex Compatibility, with ODBC
...
...
@@ -17152,7 +17190,7 @@ default value is the next value in the sequence.
@item
For date and time types other than @code{TIMESTAMP}, the default is the
appropriate ``zero'' value for the type. For the first @code{TIMESTAMP}
appropriate zero value for the type. For the first @code{TIMESTAMP}
column in a table, the default value is the current date and time.
@xref{Date and time types}.
...
...
@@ -17187,7 +17225,7 @@ You must use the @code{PRIMARY KEY(index_col_name, ...)} syntax.
@item
If the @code{PRIMARY} or @code{UNIQUE} key consists of only one column and this
is of type integer, you can also refer to it as @code{_rowid}
(new in 3.23.11).
(new in Version 3.23.11).
@item
If you don't assign a name to an index, the index will be assigned the same
...
...
@@ -17204,7 +17242,7 @@ Only the @code{MyISAM} table type supports indexes on columns that can have
@code{NOT NULL} or an error results.
@item
With @code{col_name(length)} syntax, you can specify an index which
With @code{col_name(length)} syntax, you can specify an index that
uses only a part of a @code{CHAR} or @code{VARCHAR} column. This can
make the index file much smaller.
@xref{Indexes}.
...
...
@@ -17227,7 +17265,7 @@ When you use @code{ORDER BY} or @code{GROUP BY} with a @code{TEXT} or
@xref{BLOB, , @code{BLOB}}.
@item
In @strong{MySQL} 3.23.23 or later, you can also create special
In @strong{MySQL} Version 3.23.23 or later, you can also create special
@strong{FULLTEXT} indexes. They are used for full-text search. Only the
@code{MyISAM} table type supports @code{FULLTEXT} indexes. They can be created
only from @code{VARCHAR} and @code{TEXT} columns.
...
...
@@ -17235,7 +17273,7 @@ Indexing always happens over the entire column, partial indexing is not
supported. See @ref{MySQL full-text search} for details of operation.
@item
The @code{FOREIGN KEY}, @code{CHECK} and @code{REFERENCES} clauses don't
The @code{FOREIGN KEY}, @code{CHECK}, and @code{REFERENCES} clauses don't
actually do anything. The syntax for them is provided only for compatibility,
to make it easier to port code from other SQL servers and to run applications
that create tables with references.
...
...
@@ -17254,32 +17292,32 @@ row length = 1
+ (number of variable-length columns)
@end example
@item The @code{table_options} and @code{SELECT} options is only
implemented in @strong{MySQL} 3.23 and above.
@item The @code{table_options} and @code{SELECT} options are only
implemented in @strong{MySQL} Version 3.23 and above.
The different table types are:
@multitable @columnfractions .20 .80
@item BDB or Berkeley_db @tab Transactionsafe tables @xref{BDB}.
@item BDB or Berkeley_db @tab Transaction-safe tables @xref{BDB}.
@item HEAP @tab The data for this table is only stored in memory. @xref{HEAP}.
@item ISAM @tab The original table handler. @xref{ISAM}.
@item MERGE @tab A collection of MyISAM tables used as one table @xref{MERGE}.
@item MERGE @tab A collection of MyISAM tables used as one table. @xref{MERGE}.
@item MyISAM @tab The new binary portable table handler. @xref{MyISAM}.
@end multitable
@xref{Table types}.
The other table options are used to optimize the behavior of the
table. In most cases, you don't have to specify any of them.
The options work for all table types, if not otherwise indicated.
The options work for all table types, if not otherwise indicated:
@multitable @columnfractions .20 .80
@item @code{AUTO_INCREMENT} @tab The next auto_increment value you want to set for your table (MyISAM)
@item @code{AUTO_INCREMENT} @tab The next auto_increment value you want to set for your table (MyISAM).
@item @code{AVG_ROW_LENGTH} @tab An approximation of the average row length for your table. You only need to set this for tables with variable size records.
@item @code{CHECKSUM} @tab Set this to 1 if you want @strong{MySQL} to maintain a checksum for all rows (makes the table a little slower to update but makes it easier to find corrupted tables) (MyISAM)
@item @code{COMMENT} @tab A 60 character comment for your table
@item @code{MAX_ROWS} @tab Max number of rows you plan to store in the table
@item @code{MIN_ROWS} @tab Minimum number of rows you plan to store in the table
@item @code{PACK_KEYS} @tab Set this to 1 if you want to have smaller index. This usually makes updates slower and reads faster (MyISAM, ISAM).
@item @code{CHECKSUM} @tab Set this to 1 if you want @strong{MySQL} to maintain a checksum for all rows (makes the table a little slower to update but makes it easier to find corrupted tables) (MyISAM).
@item @code{COMMENT} @tab A 60-character comment for your table.
@item @code{MAX_ROWS} @tab Max number of rows you plan to store in the table.
@item @code{MIN_ROWS} @tab Minimum number of rows you plan to store in the table.
@item @code{PACK_KEYS} @tab Set this to 1 if you want to have a smaller index. This usually makes updates slower and reads faster (MyISAM, ISAM).
@item @code{PASSWORD} @tab Encrypt the @code{.frm} file with a password. This option doesn't do anything in the standard @strong{MySQL} version.
@item @code{DELAY_KEY_WRITE} @tab Set this to 1 if want to delay key table updates until the table is closed (MyISAM).
@item @code{ROW_FORMAT} @tab Defines how the rows should be stored (for the future).
...
...
@@ -17300,14 +17338,14 @@ many numbers that are the same. Prefix compression means that every
key needs one extra byte to indicate how many bytes of the previous key are
the same for the next key (note that the pointer to the row is stored
in high-byte-first-order directly after the key, to improve
compression. This means that if you have many equal keys on two rows
compression.) This means that if you have many equal keys on two rows
in a row, all following 'same' keys will usually only take 2 bytes
(including the pointer to the row). Compare this to the ordinary case
where the following keys will take storage_size_for_key +
pointer_size (usually 4). On the other hand, if all keys are
totally different, you will lose 1 byte per key, if the key isn't a
key that can have @code{NULL} values (In this case the packed key length will
be stored in the same byte that is used to mark if a key is @code{NULL}).
be stored in the same byte that is used to mark if a key is @code{NULL}.)
@item
If you specify a @code{SELECT} after the @code{CREATE STATEMENT},
...
...
@@ -17324,16 +17362,16 @@ This will create a @code{HEAP} table with 3 columns. Note that the table will
automatically be deleted if any errors occur while copying data
into the table.
@item
The @code{RAID_TYPE} option will help you to break the 2G/4G limit on OSes
that don't support big files. You can get also more speed from the I/O
bottleneck by putting @code{RAID} directories on different physical disks.
@code{RAID_TYPE} will work on any OS, as long as you have configured
@strong{MySQL} with @code{--with-raid}. For now the only allowed
The @code{RAID_TYPE} option will help you to break the 2G/4G limit on
Operating Systems that don't support big files. You can get also more speed
from the I/O bottleneck by putting @code{RAID} directories on different
physical disks. @code{RAID_TYPE} will work on any OS, as long as you have
configured @strong{MySQL} with @code{--with-raid}. For now the only allowed
@code{RAID_TYPE} is @code{STRIPED} (@code{1} and @code{RAID0} are aliases
for this).
If you specify @code{RAID_TYPE=STRIPED} for a @code{MyISAM} table,
@code{MyISAM} will create @code{RAID_CHUNKS} sub-directories named 00,
@code{MyISAM} will create @code{RAID_CHUNKS} subdirectories named 00,
01, 02 in the database directory. In each of these directories
@code{MyISAM} will create a @code{table_name.MYD}. When writing data
to the data file, the @code{RAID} handler will map the first
...
...
@@ -17343,18 +17381,18 @@ to the data file, the @code{RAID} handler will map the first
@code{UNION} is used when you want to use a collection of identical
tables as one. This only works with MERGE tables. @xref{MERGE}.
For the moment you need to have @code{SELECT}, @code{UPDATE} and
For the moment you need to have @code{SELECT}, @code{UPDATE}, and
@code{DELETE} privileges on the tables you map to a @code{MERGE} table.
All mapped tables must be in the same database as the @code{MERGE} table.