473,761 Members | 7,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alter a primary key auto increment column?

I need to change my primary key column type from smallint to int.
I have tried:
ALTER TABLE livegroup MODIFY id INT UNSIGNED NOT NULL AUTO_INCREMENT;
But get an error message certainly since my id-column is primary key
and references other tables as well.

How can I come around this problem?
Need help

/Martin

This is my table definition

livegroup (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
type VARCHAR(60) NOT NULL,
name CHAR(60) NOT NULL,
public TINYINT NOT NULL,
creator SMALLINT UNSIGNED NOT NULL,
lastmodified TIMESTAMP(8),
PRIMARY KEY (id),
INDEX (creator),
FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE
) TYPE=INNODB;

livegroups (
data_id SMALLINT UNSIGNED NOT NULL,
livegroup_id SMALLINT UNSIGNED NOT NULL,
PRIMARY KEY (data_id, livegroup_id),
INDEX (data_id),
INDEX (livegroup_id),
FOREIGN KEY (data_id) REFERENCES livedata (id) ON DELETE CASCADE,
FOREIGN KEY (livegroup_id) REFERENCES livegroup (id) ON DELETE
CASCADE
) TYPE=INNODB;
Jul 20 '05 #1
1 28320
"Lannsjo" <la*****@home.s e> wrote in message
I need to change my primary key column type from smallint to int.
I have tried:
ALTER TABLE livegroup MODIFY id INT UNSIGNED NOT NULL AUTO_INCREMENT;
But get an error message certainly since my id-column is primary key
and references other tables as well.
Just thinking out aloud, what if you alter the table that uses the id-column
as a foreign key? Here are the steps I'd try:

(1) alter table livegroups and make livegroups.live group_id an int.

If that doesn't work

(1a) drop the foreign key relationship on livegroups.live group_id =
livegroup.id.
(1b) alter table livegroups and make livegroups.live group_id an int.

If that doesn't work

(1a) drop the foreign key relationship on livegroups.live group_id =
livegroup.id.
(1b) drop the index on livegroup_id.
(1c) alter table livegroups and make livegroups.live group_id an int.

(2) Similarly, alter table livegroup to make livegroup.id an int. Try the
version where you just change the column, if that doesn't work drop the
primary key then alter the column.

(3) In the base table livegroup add back the index if you had to drop it.

(4) In the dependent tables add back the index and foreign key relatinoship
if you had to drop it.
ALTER TABLE livegroup MODIFY id INT UNSIGNED NOT NULL AUTO_INCREMENT; How can I come around this problem?
Need help

/Martin

This is my table definition

livegroup (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
type VARCHAR(60) NOT NULL,
name CHAR(60) NOT NULL,
public TINYINT NOT NULL,
creator SMALLINT UNSIGNED NOT NULL,
lastmodified TIMESTAMP(8),
PRIMARY KEY (id),
INDEX (creator),
FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE
) TYPE=INNODB;

livegroups (
data_id SMALLINT UNSIGNED NOT NULL,
livegroup_id SMALLINT UNSIGNED NOT NULL,
PRIMARY KEY (data_id, livegroup_id),
INDEX (data_id),
INDEX (livegroup_id),
FOREIGN KEY (data_id) REFERENCES livedata (id) ON DELETE CASCADE,
FOREIGN KEY (livegroup_id) REFERENCES livegroup (id) ON DELETE
CASCADE
) TYPE=INNODB;

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4517
by: Eric | last post by:
Let me start by saying that I'm still very new at PHP/MySql and will take any advice. :-) The issues is that every once in a while users get an error when they use this code. I believe the issue is that I'm copying the primary key as well as the other data in the row. So, my thoughts on fixing this are to just select everything but the 'pkey' column, but I'm not sure what would result from that. Would MySql use the next auto...
0
719
by: Nick | last post by:
Is it possible to have multiple auto increments in one column? Say I have two tables... 1. table 'messageboards' with fields ('id' , 'name') 2. table 'messagethreads' with fields ('id' , 'messagethread' , 'messageboard_id') The 'messagethreads.id' column could have multiple auto increments. Then I could easily query a messageboard with ("SELECT * FROM
1
11495
by: Lannsjo | last post by:
I need to change my primary key column type from smallint to int. I have tried: ALTER TABLE livegroup MODIFY id INT UNSIGNED NOT NULL AUTO_INCREMENT; But get an error message certainly since my id-column is primary key and references other tables as well. How can I come around this problem? Need help /Martin
2
21356
by: me | last post by:
I would like to add an Identity to an existing column in a table using a stored procedure then add records to the table and then remove the identity after the records have been added or something similar. here is a rough idea of what the stored procedure should do. (I do not know the syntax to accomplish this can anyone help or explain this? Thanks much, CBL
3
5674
by: Metal Dave | last post by:
Hello, A script we run against the database as part of the upgrade of our product is failing with the following message: ALTER TABLE ALTER COLUMN EncodedID failed because STATISTICS hind_61_3 accesses this column The line that fails is:
2
31503
by: RamaKrishna Narla | last post by:
In MS SQL Server, I have the following tables with some data in it. create table table1 ( column1 varchar(32), column2 int not null, column10 varchar(255), ..... primary key (column1, column2), );
11
1988
by: Greg P | last post by:
I'm using VB 2005, and have drug and dropped datagridviews onto my form. The default code that is generated for inserts tries to insert a value for the auto generated primary key. Below is the generated code. I put ***** around the problematic code. I've tried just removing this and it doesn't seem to work. There may be more generated code I don't know about. I could remove it but I am planning on doing a lot of refreshing of the data...
2
8711
by: alexs | last post by:
Chaps, I'm starting to play with db2 V9.1 and am writing a stored procedure to manage accounting records from oiur RADIUS server. I've got an XML aware table with an auto increment primary key, a few sql columns and an XML column. For every XML object I'm inserting, i'd lke to have an ID attribute that has the same value as the SQL primary key that'll be created upon executing the insert.
2
1596
by: musicbizguy | last post by:
Hello everyone. I'm a noob to MySql, so I'm hoping this is easy and I apologise in advance if I've got the terminology all wrong; I've searched the forum but couldn't find an answer. I have a Joomla database with a lot of imported data from various sources. The table 'jos_content' has an indexing column 'ordering' (distinct from the primary auto incrementing index 'id') which affects how rows are ordered in the admin backend of Joomla. I...
5
14690
by: giandeo | last post by:
Hello Dr. B Your solution is amazing. It works...........Wowh. Thank you so much. I still have one problem. I am using the autonumber of the access database as primary key. When I imported the data in MS SQL Server, the autonumber got converted into integer. I do not know how to go to the bottom of the database and increment that field while adding data. Could you please give your valuable suggestions
0
9522
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
10111
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
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...
0
9765
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
8770
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...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
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
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.