?
Solved

set primary key in existing table and field

Posted on 2006-07-16
2
Medium Priority
?
645 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 500 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …
Suggested Courses

765 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