• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 654
  • Last Modified:

set primary key in existing table and field

hi, no matter how much i google search this, i cant find the answer.

how do i set the primary key and auto_increment on an already existing field in a table.

For the history, im copying 35 tables in a database with different table names using:

$table = "CREATE TABLE IF NOT EXISTS ".$username."_banner SELECT * FROM default_banner";
mysql_query($table);

but this does not copy over the primary key and auto_increment settings.
0
Erron
Asked:
Erron
  • 2
1 Solution
 
Raynard7Commented:
alter table `test`.`tablename1` change `a` `a` int (10)   NOT NULL AUTO_INCREMENT , add primary key (`a` )

Will change a table (tablename1) in the test schema -
it will change field `a` to an autoincrement field and will be the primary key.
0
 
Raynard7Commented:
If there are null values it will not work
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now