Jump to content

updating primary key after its been created


leeming

Recommended Posts

hey, ive tried to run this query both in myPHPadmin (point and click) aswell as the sql code stright in, but neither work...
Can i not change field properties on a primary key field? im trying to put NULL on, so i can insert a user id of "0".

[code]
  mysql_query("ALTER TABLE `member` CHANGE `mid` `mid` INT( 15 ) NULL AUTO_INCREMENT")or die('1 : '.mysql_error());
[/code]

N.B 'mid' been my id field, ([b]M[/b]ember[b]ID[/b])
Link to comment
Share on other sites

I'm not 100% positive but I don't think you can have a NULL value on a primary key, or an auto increment column. FYI, in MySQL, 0 and NULL are not the same. You could still have a value of 0 without declaring the column as NULL. But I'm pretty sure you can't have a primary key with a NULL value, and you can't have an auto increment column with a 0 value.....but I may be wrong about that last one. Try that and see if it works.
Link to comment
Share on other sites

well i only wanted to know, so that my member id "0" can be shown as "ADMIN"... if not, i will just have to hard code all the pages linked to showing "member info" with some kind of IF(mid == 0) kinda of statment... just would of liked to be able to just have the "ADMIN" 'user' as in the database
Link to comment
Share on other sites

You seem to be missing the idea behind primary keys - they are primarily there to identfy a unique record.

You don't need to do anything with them as the database does that itself. If you try to do what you have suggested and have more than 1 admin then the database would NEVER let you have 2 primary key values of 0 - it couldn't be a key then!

You are better off adding a field to the table indicating the users permissions level....
Link to comment
Share on other sites

[quote author=ToonMariner link=topic=99898.msg393803#msg393803 date=1152408365]
You seem to be missing the idea behind primary keys - they are primarily there to identfy a unique record.

You don't need to do anything with them as the database does that itself. If you try to do what you have suggested and have more than 1 admin then the database would NEVER let you have 2 primary key values of 0 - it couldn't be a key then!

You are better off adding a field to the table indicating the users permissions level....
[/quote]

no just 1 admin account.. ok i will explain a bit...


parts of my site.. eg in site mail system... shows who the mail is from, and if i had memberid for "admin" = '0' then it would act like a normal database call..
if i cant do what im trying with the id for = '0' then i will have to put in (every where, "Admin" account details are shown.. eg havings IF(user = admin) every where...)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.