Jump to content

forgot to insert primary key colum?


n8w

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.