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; 1 28279
"Lannsjo" <la*****@home.se> 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.livegroup_id an int.
If that doesn't work
(1a) drop the foreign key relationship on livegroups.livegroup_id =
livegroup.id.
(1b) alter table livegroups and make livegroups.livegroup_id an int.
If that doesn't work
(1a) drop the foreign key relationship on livegroups.livegroup_id =
livegroup.id.
(1b) drop the index on livegroup_id.
(1c) alter table livegroups and make livegroups.livegroup_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; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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' ,...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
| |