blueman378 Posted December 26, 2007 Share Posted December 26, 2007 hi guys i have a table that looks like this: CREATE TABLE `games` ( `gSwfFile` varchar(100) NOT NULL, `gName` varchar(100) NOT NULL, `gThumb` varchar(100) NOT NULL, `gDescription` varchar(100) NOT NULL, `gplays` smallint(5) unsigned NOT NULL default '0', `RId` smallint(5) unsigned NOT NULL default '0', `category` varchar(100) NOT NULL, `keyword` varchar(100) NOT NULL, UNIQUE KEY `gName` (`gName`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; now what i want is to add in a column called RId and have it auto incriment, however when i try i get.. #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key any ideas what i have to do? Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/ Share on other sites More sharing options...
PHP_PhREEEk Posted December 26, 2007 Share Posted December 26, 2007 I think if you remove the unique key for `gName`, then it will accept your new field. You don't need to remove gName, just the unique designation. Give it a try... PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423355 Share on other sites More sharing options...
blueman378 Posted December 26, 2007 Author Share Posted December 26, 2007 thanks, what does the unique key acctually do? Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423359 Share on other sites More sharing options...
redarrow Posted December 26, 2007 Share Posted December 26, 2007 update that colum with +1 `RId` int(5) unsigned NOT NULL default '0', $sql=" update what_ever set Rid=Rid+1 where what_ever='$what_ever'"; Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423360 Share on other sites More sharing options...
PHP_PhREEEk Posted December 26, 2007 Share Posted December 26, 2007 thanks, what does the unique key acctually do? It requires that every record in the table has a unique value in the gName field. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423361 Share on other sites More sharing options...
blueman378 Posted December 26, 2007 Author Share Posted December 26, 2007 hmm i deleted that and tried to set that column as the unique key and get: SQL query: ALTER TABLE `games` ADD UNIQUE ( `RId` ) MySQL said: Documentation #1062 - Duplicate entry '0' for key 1 ??? Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423362 Share on other sites More sharing options...
blueman378 Posted December 26, 2007 Author Share Posted December 26, 2007 ah got it, i already had some that info that was created before the column so it meant that they were defined as zero... sily me Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423364 Share on other sites More sharing options...
Barand Posted December 26, 2007 Share Posted December 26, 2007 Create it with CREATE TABLE `games` ( `gSwfFile` varchar(100) NOT NULL, `gName` varchar(100) NOT NULL, `gThumb` varchar(100) NOT NULL, `gDescription` varchar(100) NOT NULL, `gplays` smallint(5) unsigned NOT NULL default '0', `RId` smallint(5) unsigned NOT NULL auto_increment primary key, `category` varchar(100) NOT NULL, `keyword` varchar(100) NOT NULL, UNIQUE KEY `gName` (`gName`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; or mod existing table with ALTER TABLE `games` MODIFY COLUMN `RId` INTEGER NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY(`RId`); Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423367 Share on other sites More sharing options...
blueman378 Posted December 26, 2007 Author Share Posted December 26, 2007 well i have already created this topic so i might as well ask here, i am trying out a script and i now get this error: Fatal error: Function name must be a string in C:\wamp\www\admin\gameinstaller.php on line 173 but line 173 is $sql("INSERT INTO ".games." Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423368 Share on other sites More sharing options...
PHP_PhREEEk Posted December 26, 2007 Share Posted December 26, 2007 I hadn't noticed that RId was already in the table... I solved it by creating a Primary Key for RId, then selecting auto-increment for it. Worked fine. Glad you got it solved anyways... PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423369 Share on other sites More sharing options...
PHP_PhREEEk Posted December 26, 2007 Share Posted December 26, 2007 well i have already created this topic so i might as well ask here, i am trying out a script and i now get this error: Fatal error: Function name must be a string in C:\wamp\www\admin\gameinstaller.php on line 173 but line 173 is $sql("INSERT INTO ".games." You need $sql = "INSERT INTO ".games." // etc PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423370 Share on other sites More sharing options...
redarrow Posted December 26, 2007 Share Posted December 26, 2007 i didnt even see that there was no primary_key and auto_increment my example was using the update statement as a secound increment dam dam dam.... what would we ever do without barand (happy xmas barand and happy new year) Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423371 Share on other sites More sharing options...
blueman378 Posted December 26, 2007 Author Share Posted December 26, 2007 thanks guys all is solved merry xmas and a ahppy new year to you all, haha i gotta hurry with this site its a bday prezzie 4 someone in feb lol Quote Link to comment https://forums.phpfreaks.com/topic/83224-solved-a-new-auto-incriment-column-in-mysql-and-another-mydql-question/#findComment-423372 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.