For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > February 2007 > Re: [PHP-DB] Trying to add primary key to existing database.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] Trying to add primary key to existing database.
Chris

2007-02-04, 6:58 pm

Chris Carter wrote:
> Hi,
>
> I have a database, which was till now, not having any primary key defined. I
> thought I would not need it but now I think I do (based on the suggestions
> from my prior postings). I am now trying to insert the primary key in an
> already existing database. There was not even an index defined earlier
> (sorry, if it looks strange). There are many columns that have same names
> this means that I cannot make that column the primary key.
>
> I have now got an idea to first define index on the table and then make the
> index thing the primary key. I have mySql on cPanel. please advice how to
> achieve this on an existing database in cPanel php admin.
>
> Any link or steps would help. I tried it myself but there is something it
> wants to tell me, that I am not sure about.


Most likely not everything can be done through phpmyadmin, however you
can add your own primary key easily:

alter table tablename add id int not null auto_increment primary key;

See http://dev.mysql.com/doc/refman/4.1/en/alter-table.html

--
Postgresql & php tutorials
http://www.designmagick.com/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com