
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.thelinuxwiki.com/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.thelinuxwiki.com/index.php?action=history&amp;feed=atom&amp;title=Howto_create_mysql_table</id>
		<title>Howto create mysql table - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.thelinuxwiki.com/index.php?action=history&amp;feed=atom&amp;title=Howto_create_mysql_table"/>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Howto_create_mysql_table&amp;action=history"/>
		<updated>2026-04-29T00:16:00Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.21.5</generator>

	<entry>
		<id>http://www.thelinuxwiki.com/index.php?title=Howto_create_mysql_table&amp;diff=462&amp;oldid=prev</id>
		<title>Nighthawk at 01:26, 27 July 2013</title>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Howto_create_mysql_table&amp;diff=462&amp;oldid=prev"/>
				<updated>2013-07-27T01:26:28Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 01:26, 27 July 2013&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;select database in which to create a new tables&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;select database in which to create a new tables&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; use ''database_name'';&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;mysql&amp;gt; &lt;/ins&gt;use ''database_name'';&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; mysql&amp;gt; CREATE TABLE example (&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; mysql&amp;gt; CREATE TABLE example (&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Nighthawk</name></author>	</entry>

	<entry>
		<id>http://www.thelinuxwiki.com/index.php?title=Howto_create_mysql_table&amp;diff=461&amp;oldid=prev</id>
		<title>Nighthawk at 01:25, 27 July 2013</title>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Howto_create_mysql_table&amp;diff=461&amp;oldid=prev"/>
				<updated>2013-07-27T01:25:58Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 01:25, 27 July 2013&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A very basic CREATE TABLE statement which should work in any SQL database:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A very basic CREATE TABLE statement which should work in any SQL database:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;select database in which to create a new tables&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; use ''database_name'';&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; mysql&amp;gt; CREATE TABLE example (&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; mysql&amp;gt; CREATE TABLE example (&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Nighthawk</name></author>	</entry>

	<entry>
		<id>http://www.thelinuxwiki.com/index.php?title=Howto_create_mysql_table&amp;diff=314&amp;oldid=prev</id>
		<title>Nighthawk: Pushed from Themanclub.</title>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Howto_create_mysql_table&amp;diff=314&amp;oldid=prev"/>
				<updated>2013-05-17T15:27:40Z</updated>
		
		<summary type="html">&lt;p&gt;Pushed from Themanclub.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Basic CREATE TABLE statement&lt;br /&gt;
&lt;br /&gt;
A very basic CREATE TABLE statement which should work in any SQL database:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; CREATE TABLE example (&lt;br /&gt;
         id INT,&lt;br /&gt;
         data VARCHAR(100)&lt;br /&gt;
       );&lt;br /&gt;
  Query OK, 0 rows affected (0.03 sec)&lt;br /&gt;
&lt;br /&gt;
Creating a table with a particular storage engine&lt;br /&gt;
&lt;br /&gt;
MySQL provides a variety of different table types with differing levels of functionality. The usual default, and most widely used, is MyISAM. Other storage types must be explicitly defined:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt;  CREATE TABLE example_innodb (&lt;br /&gt;
          id INT,&lt;br /&gt;
          data VARCHAR(100)&lt;br /&gt;
        ) TYPE=innodb;&lt;br /&gt;
  Query OK, 0 rows affected (0.03 sec)&lt;br /&gt;
&lt;br /&gt;
Note that beginning with MySQL 4.1 ENGINE=innodb is the preferred method of defining the storage type.&lt;br /&gt;
&lt;br /&gt;
Use SHOW CREATE TABLE (see below) to check that MySQL has created the table as you defined it.&lt;br /&gt;
Creating a table with auto_increment&lt;br /&gt;
&lt;br /&gt;
Often you'll want to be able to automatically assign a sequential value to a column:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; CREATE TABLE example_autoincrement (&lt;br /&gt;
         id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;
         data VARCHAR(100)&lt;br /&gt;
       );&lt;br /&gt;
  Query OK, 0 rows affected (0.01 sec)&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; INSERT INTO example_autoincrement (data)&lt;br /&gt;
    -&amp;gt;      VALUES ('Hello world');&lt;br /&gt;
  Query OK, 1 row affected (0.01 sec)&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; SELECT * FROM  example_autoincrement;&lt;br /&gt;
  +----+-------------+&lt;br /&gt;
  | id | data        |&lt;br /&gt;
  +----+-------------+&lt;br /&gt;
  |  1 | Hello world |&lt;br /&gt;
  +----+-------------+&lt;br /&gt;
  1 row in set (0.01 sec)&lt;br /&gt;
&lt;br /&gt;
Creating a table with the current timestamp&lt;br /&gt;
&lt;br /&gt;
Often it's useful to have an automatic timestamp on each record. The MySQL special datatype TIMESTAMP enables you to keep track of changes to a record:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; CREATE TABLE example_timestamp (&lt;br /&gt;
         id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;
         data VARCHAR(100),&lt;br /&gt;
         cur_timestamp TIMESTAMP(8)&lt;br /&gt;
       );&lt;br /&gt;
  Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; INSERT INTO example_timestamp (data)&lt;br /&gt;
            VALUES ('The time of creation is:');&lt;br /&gt;
  Query OK, 1 row affected (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; SELECT * FROM example_timestamp;&lt;br /&gt;
  +----+--------------------------+---------------------+&lt;br /&gt;
  | id | data                     | cur_timestamp       |&lt;br /&gt;
  +----+--------------------------+---------------------+&lt;br /&gt;
  |  1 | The time of creation is: | 2004-12-01 20:37:22 |&lt;br /&gt;
  +----+--------------------------+---------------------+&lt;br /&gt;
  1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; UPDATE example_timestamp &lt;br /&gt;
          SET data='The current timestamp is: ' &lt;br /&gt;
        WHERE id=1;&lt;br /&gt;
  Query OK, 1 row affected (0.03 sec)&lt;br /&gt;
  Rows matched: 1  Changed: 1  Warnings: 0&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; SELECT * FROM example_timestamp;&lt;br /&gt;
  +----+---------------------------+---------------------+&lt;br /&gt;
  | id | data                      | cur_timestamp       |&lt;br /&gt;
  +----+---------------------------+---------------------+&lt;br /&gt;
  |  1 | The current timestamp is: | 2004-12-01 20:38:55 |&lt;br /&gt;
  +----+---------------------------+---------------------+&lt;br /&gt;
  1 row in set (0.01 sec)&lt;br /&gt;
&lt;br /&gt;
The column cur_timestamp is automagically updated every time the record is changed.&lt;br /&gt;
Creating a table with TIMESTAMP DEFAULT NOW()&lt;br /&gt;
&lt;br /&gt;
MySQL supports the construct TIMESTAMP DEFAULT NOW() only from verson 4.1:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  CREATE TABLE example_default_now (&lt;br /&gt;
    id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,&lt;br /&gt;
    data VARCHAR(100),&lt;br /&gt;
    created TIMESTAMP DEFAULT NOW()&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
In this case the column created retains its initial value and is not changed during subsequent updates.&lt;br /&gt;
&lt;br /&gt;
For versions prior to 4.1, the only workaround is to create two timestamp columns in a table, and explicitly set the second one when inserting the record. Remember: the first TIMESTAMP will be automagically updated on each record update.&lt;br /&gt;
Viewing a table definition&lt;br /&gt;
&lt;br /&gt;
For basic information on table columns, use DESC tablename:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; DESC example;&lt;br /&gt;
  +-------+--------------+------+-----+---------+-------+&lt;br /&gt;
  | Field | Type         | Null | Key | Default | Extra |&lt;br /&gt;
  +-------+--------------+------+-----+---------+-------+&lt;br /&gt;
  | id    | int(11)      | YES  |     | NULL    |       |&lt;br /&gt;
  | data  | varchar(100) | YES  |     | NULL    |       |&lt;br /&gt;
  +-------+--------------+------+-----+---------+-------+&lt;br /&gt;
  2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Exact definition of the table:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  mysql&amp;gt; SHOW CREATE TABLE example;&lt;br /&gt;
  +---------+------------------------------------------------+&lt;br /&gt;
  | Table   | Create Table                                   |&lt;br /&gt;
  +---------+------------------------------------------------+&lt;br /&gt;
  | example | CREATE TABLE `example` (&lt;br /&gt;
    `id` int(11) default NULL,&lt;br /&gt;
    `data` varchar(100) default NULL&lt;br /&gt;
  ) ENGINE=MyISAM DEFAULT CHARSET=latin1 |&lt;br /&gt;
  +---------+------------------------------------------------+&lt;br /&gt;
  1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
(this example from MySQL 4.1) &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[category:mysql]]&lt;/div&gt;</summary>
		<author><name>Nighthawk</name></author>	</entry>

	</feed>