creating a key in a table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

creating a key in a table

Post by pelegk2 »

i want to chamge a column that is defined as :
order_id int(8) unsinged notnull
and tried to do :
alter TABLE tblprodoreder add PRIMARY KEY (order_id)
but i get "duplicate entry '0' for key 1"
what to do?
and how do i define it as autoincementae too?
thnaks i nadvance
peleg
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the key requires all values to be unique among the data in the field. So if you repeat a value, you'll get an error.

I don't remember the syntax for adding auto_increment, can't quite check it right now either.. Why not use phpMyAdmin (assuming you're using MySQL..) ?
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

the problem is that i have

Post by pelegk2 »

already defined :
order_id int(8) default 0
and beaucse of that all the rws are 0 now
and maybe beacuse of that i cant do a key!
how can i fizx it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

fix the values. :?
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

how can i fix them?

Post by pelegk2 »

to write a script that will un all over the rows and change the valued to a running numbers?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

they need to be unique among their peers, so... something like that, yeah.
Post Reply