leeming Posted July 8, 2006 Share Posted July 8, 2006 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]) Quote Link to comment https://forums.phpfreaks.com/topic/14048-updating-primary-key-after-its-been-created/ Share on other sites More sharing options...
robos99 Posted July 8, 2006 Share Posted July 8, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14048-updating-primary-key-after-its-been-created/#findComment-54926 Share on other sites More sharing options...
leeming Posted July 9, 2006 Author Share Posted July 9, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14048-updating-primary-key-after-its-been-created/#findComment-54994 Share on other sites More sharing options...
ToonMariner Posted July 9, 2006 Share Posted July 9, 2006 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 Link to comment https://forums.phpfreaks.com/topic/14048-updating-primary-key-after-its-been-created/#findComment-55000 Share on other sites More sharing options...
leeming Posted July 9, 2006 Author Share Posted July 9, 2006 [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...) Quote Link to comment https://forums.phpfreaks.com/topic/14048-updating-primary-key-after-its-been-created/#findComment-55002 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.