Jump to content

Recommended Posts

I forgot to put a primary key column in one of my tables

so when I tried to insert one called portfolio_id (int) auto_increment

it won't let me do it because it says there is duplicate values

 

is there an easy way to insert a primary key column with auto increment?

 

If not .. I figure I need to insert a column and update the values with a php script and then make it the primary key once the values are unique?

 

which everything goes smoothly up until the number 127 .. then it puts the value 127 for everything after ... 127

$sql = 'SELECT * FROM portfolio_n8w LIMIT 500';
$retid = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($retid)){
		$counter++;
		$title = $row["title"];
		$sql2 = 'UPDATE portfolio_n8w SET'
	. ' portfolio_id	= "'.$counter.'"'
	. ' WHERE'
	. ' title = "'.$title.' "  LIMIT 1';
	$retid2 = mysql_query($sql2) or die(mysql_error());
}

 

Link to comment
https://forums.phpfreaks.com/topic/163922-forgot-to-insert-primary-key-colum/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.