Author: jstephens
Date: 2006-04-20 10:34:25 +0200 (Thu, 20 Apr 2006)
New Revision: 1884
Log:
Additional example & info regarding ALTER TABLE ... ADD PRIMARY KEY and
replication. (Mats)
Modified:
trunk/refman-4.1/sql-syntax.xml
trunk/refman-5.0/sql-syntax.xml
trunk/refman-5.1/sql-syntax.xml
Modified: trunk/refman-4.1/sql-syntax.xml
===================================================================
--- trunk/refman-4.1/sql-syntax.xml 2006-04-20 06:21:38 UTC (rev 1883)
+++ trunk/refman-4.1/sql-syntax.xml 2006-04-20 08:34:25 UTC (rev 1884)
@@ -897,8 +897,38 @@
This assumes that the table <literal>t1</literal> has columns
<literal>col1</literal> and <literal>col2</literal>.
</para>
+
+ <para>
+ This set of statements will also produce a new table
+ <literal>t2</literal> identical to <literal>t1</literal>,
with
+ the addition of an <literal>AUTO_INCREMENT</literal> column:
+ </para>
+
+<programlisting>
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE T2 ADD id INT AUTO_INCREMENT PRIMARY KEY;
+INSERT INTO t2 SELECT * FROM t1 ORDER BY col1, col2;
+</programlisting>
<para>
+ <emphasis role="bold">Important</emphasis>: To guarantee the
+ same ordering on both master and slave, <emphasis>all</emphasis>
+ columns of <literal>t1</literal> must be referenced in the
+ <literal>ORDER BY</literal> clause.
+ </para>
+
+ <para>
+ Regardless of the method used to create and populate the copy
+ having the <literal>AUTO_INCREMENT</literal> column, the final
+ step is to drop the original table and then rename the copy:
+ </para>
+
+<programlisting>
+DROP t1;
+ALTER TABLE t2 RENAME t1;
+</programlisting>
+
+ <para>
See also <xref linkend="alter-table-problems"/>.
</para>
Modified: trunk/refman-5.0/sql-syntax.xml
===================================================================
--- trunk/refman-5.0/sql-syntax.xml 2006-04-20 06:21:38 UTC (rev 1883)
+++ trunk/refman-5.0/sql-syntax.xml 2006-04-20 08:34:25 UTC (rev 1884)
@@ -910,8 +910,38 @@
This assumes that the table <literal>t1</literal> has columns
<literal>col1</literal> and <literal>col2</literal>.
</para>
+
+ <para>
+ This set of statements will also produce a new table
+ <literal>t2</literal> identical to <literal>t1</literal>,
with
+ the addition of an <literal>AUTO_INCREMENT</literal> column:
+ </para>
+
+<programlisting>
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE T2 ADD id INT AUTO_INCREMENT PRIMARY KEY;
+INSERT INTO t2 SELECT * FROM t1 ORDER BY col1, col2;
+</programlisting>
<para>
+ <emphasis role="bold">Important</emphasis>: To guarantee the
+ same ordering on both master and slave, <emphasis>all</emphasis>
+ columns of <literal>t1</literal> must be referenced in the
+ <literal>ORDER BY</literal> clause.
+ </para>
+
+ <para>
+ Regardless of the method used to create and populate the copy
+ having the <literal>AUTO_INCREMENT</literal> column, the final
+ step is to drop the original table and then rename the copy:
+ </para>
+
+<programlisting>
+DROP t1;
+ALTER TABLE t2 RENAME t1;
+</programlisting>
+
+ <para>
See also <xref linkend="alter-table-problems"/>.
</para>
Modified: trunk/refman-5.1/sql-syntax.xml
===================================================================
--- trunk/refman-5.1/sql-syntax.xml 2006-04-20 06:21:38 UTC (rev 1883)
+++ trunk/refman-5.1/sql-syntax.xml 2006-04-20 08:34:25 UTC (rev 1884)
@@ -1189,8 +1189,38 @@
This assumes that the table <literal>t1</literal> has columns
<literal>col1</literal> and <literal>col2</literal>.
</para>
+
+ <para>
+ This set of statements will also produce a new table
+ <literal>t2</literal> identical to <literal>t1</literal>,
with
+ the addition of an <literal>AUTO_INCREMENT</literal> column:
+ </para>
+
+<programlisting>
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE T2 ADD id INT AUTO_INCREMENT PRIMARY KEY;
+INSERT INTO t2 SELECT * FROM t1 ORDER BY col1, col2;
+</programlisting>
<para>
+ <emphasis role="bold">Important</emphasis>: To guarantee the
+ same ordering on both master and slave, <emphasis>all</emphasis>
+ columns of <literal>t1</literal> must be referenced in the
+ <literal>ORDER BY</literal> clause.
+ </para>
+
+ <para>
+ Regardless of the method used to create and populate the copy
+ having the <literal>AUTO_INCREMENT</literal> column, the final
+ step is to drop the original table and then rename the copy:
+ </para>
+
+<programlisting>
+DROP t1;
+ALTER TABLE t2 RENAME t1;
+</programlisting>
+
+ <para>
See also <xref linkend="alter-table-problems"/>.
</para>
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r1884 - in trunk: refman-4.1 refman-5.0 refman-5.1 | jon | 20 Apr |