Solved

set primary key in existing table and field

Posted on 2006-07-16
2
614 Views
Last Modified: 2008-02-26
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
Comment
Question by:Erron
  • 2
2 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 125 total points
Comment Utility
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
 
LVL 35

Expert Comment

by:Raynard7
Comment Utility
If there are null values it will not work
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now