473,654 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loading initial values into auto_increment column

2 New Member
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 1618
bcm
2 New Member
I believe the answer is to use the Sql-Mode setting NO_AUTO_VALUE_O N_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
10208
by: Nico v. Rossum | last post by:
Hi * How can reset a auto_incremet collumn so it starts from 1 TIA
2
492
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 AUTO_INCREMENT, name varchar(15), primary key(UserID)); >insert into abs(name) VALUES ('Elton'), ('Andy'), ('Peter'); >select * from abs;
4
1926
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 has numerous tables in the 200 column range, with several thousand rows of data. A consulting review prior to my involvement stressed the wasted space and database speed as the major impetus for normalization. Although the db actually works fairly...
2
1322
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 the control's initial values without their events getting fired. It seems to be a pretty common requirement. Any quick way of doing this? (short of using a boolean flag!)
5
12229
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. The ID is a member of the keys array. I then create a DataView dv over the table, and sort it by Display and ID column (in case of duplicate Display). I then set my DataGrid.DataSource = dv; I then load the datatable with my rows, and this is...
1
3351
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 Me.plcTabViews.Controls.Add(LoadControl("test.ascx")). There are up to 30 possibilities which are decided by CASE statements and keeps one from loading up onto another. However, I'm running into a unique error... Failed to load viewstate. The control tree into which viewstate is...
1
1727
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 field is specified as or PRIMARY KEY or UNIQUE? Cheers Phil
2
1473
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 more related Payments. Now, I want to combine the sum of all Payments and the last Payment in one row. select Orders.SeqNr,
1
1318
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
8376
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8708
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.