<A Z Wrote>
Hi,

Is there a function to fill an integer column in
incremental order (1,2,..,n).
Cannot use Auto_Increment as the table has another
primary key.

regards
</A Z>

Hello A Z,

You can declare a column as AUTO_INCREMENT without designating it as a
primary key.  However, having more than 1 auto_increment column per table
is prohibited and the column you declare must be indexed (but not
necessarily as the primary key).

>From the manual:
(http://dev.mysql.com/doc/mysql/en/CREATE_TABLE.html)
      An integer column can have the additional attribute AUTO_INCREMENT.
      When you insert a value of NULL (recommended) or 0 into an indexed
      AUTO_INCREMENT column, the column is set to the next sequence value.
      Typically this is value+1, where value is the largest value for the
      column currently in the table. AUTO_INCREMENT sequences begin with 1.
      See section 20.2.3.32 mysql_insert_id(). As of MySQL 4.1.1,
      specifying the NO_AUTO_VALUE_ON_ZERO flag for the --sql-mode server
      option or the sql_mode system variable allows you to store 0 in
      AUTO_INCREMENT columns as 0 without generating a new sequence value.
      See section 5.2.1 mysqld Command-Line Options. Note: There can be
      only one AUTO_INCREMENT column per table, it must be indexed, and it
      cannot have a DEFAULT value. As of MySQL 3.23, an AUTO_INCREMENT
      column will work properly only if it contains only 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 you don't accidentally get an AUTO_INCREMENT column that
      contains 0. For MyISAM and BDB tables, you can specify an
      AUTO_INCREMENT secondary column in a multiple-column key. See section
      3.6.9 Using AUTO_INCREMENT. To make MySQL compatible with some ODBC
      applications, you can find the AUTO_INCREMENT value for the last
      inserted row with the following query:
      SELECT * FROM tbl_name WHERE auto_col IS NULL

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to