473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Loading initial values into auto_increment column

2
I am migrating a database to MySQL 5.0. Several tables should have their primary key as an auto_increment integer. The database being copied has records with the primary key beginning with zero (0). These keys are foreign keys so it is not desirable to change their values.

Here is what I have been trying:
(1) Truncate table <tablename>;
(2) Alter table <tablename> modify recid integer not null default 0;
(3) <insert rows into table>
(4) Alter table <tablename> modify recid integer not null auto_increment;

When I execute statement number 4, above, if the recid has been inserted with a value of zero, then MySql is changing the zero to one.

How can I get MySql to let me load my values into the column and to set the auto_increment to the max(recid) + 1 ?
Apr 15 '07 #1
1 1604
bcm
2
I believe the answer is to use the Sql-Mode setting NO_AUTO_VALUE_ON_ZERO.

http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html

http://www.xaprb.com/blog/2006/04/23/explicit-inserts-into-auto_increment-columns-in-mysql/
Apr 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nico v. Rossum | last post by:
Hi * How can reset a auto_incremet collumn so it starts from 1 TIA
2
by: hjyn | last post by:
Hi, how can I add char to auto_increment? For example, the auto_increment is for integer, I want to add a character at the front of that number. Ex: >create table abs (UserID INT(3) NOT NULL...
4
by: Bill Stock | last post by:
The few times in the past that I've loaded unbound data, I've tended to cheat and use temp tables (not really unbound) or use code for small datasets. I'm currently involved in a project that...
2
by: Norvin Laudon | last post by:
Hi, I have a form with various controls which are wired to events when their data, listindex, or whatever changes. Simple question: As I'm loading the form (in the constructor), I need to set...
5
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. ...
1
by: John Cosmas | last post by:
I've got a page which loads up a different user control into a placeholder control every time a button is clicked on the parent page. I use a statement like...
1
by: Phil Latio | last post by:
Newbie questions here... Reading the MySQL manual regarding InnoDB databases, can someone confirm that: 1. if the server is rebooted, AUTO_INCREMENT reverts back to 1? 2. what happens if the...
2
by: Stefan van Roosmalen | last post by:
Hi there, I have Orders and Payments. Sometimes the Orders do not have Payments. So, I decided to use LEFT JOIN. Furthermore, some Orders have 1 related Payment, and some Orders have 2 or even...
1
by: mostafijur | last post by:
Hello, My database table containing a column name P_ID Field Extra = P_ID, Type = int(11), Null = NO, Key = PRI, Default = NULL, Extra = auto_increment
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.