Solved

set primary key in existing table and field

Posted on 2006-07-16
2
631 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
ID: 17119021
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
ID: 17119022
If there are null values it will not work
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 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