MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 4th, 2011, 05:41 PM
sibal sibal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 1 sibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 42 sec
Reputation Power: 0
SQL problem

i actually very new to SQL never had any academic training what ever Little i have learn it's from expert's tutorials and opinion or dissociation on WEB,

recently i have a problem on my website witch is full of spam tru to get lot's of help but none have any answer so i try my self to solve it

so

i was up to delete Duplicate posts and i was success but the real problem came up on SQL.

I want to change the value of mybb_posts > Structure > AUTO_INCREMENT it's give me error

Code:
Error
SQL query:

ALTER TABLE  `mybb_posts` CHANGE  `pid`  `pid` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT

MySQL said: 

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key 



but in original mybb_posts > Structure > AUTO_INCREMENT it's fine can any one explain what i should do ??

screen shoot
URL
Code:
http://i.imgur.com/QHQsJ.jpg


ok let me explain what did i actually do

To remove duplicate post i write a sql query


CREATE TABLE mybb_postsx as
SELECT * FROM mybb_posts WHERE 1 GROUP BY subject;

all duplicate post was remove but the thread was there so i write down again this

CREATE TABLE mybb_threadsx as
SELECT * FROM mybb_threads WHERE 1 GROUP BY subject;

every thing become perfect but when i post something, it's show the thread name but there was no post created, i have look in to the database the post have submitted and saved but the PID and TID was 0 .. i look back to the old table and the value settings i found the AUTO_INCREMENT disabled on my new table .. can any one please light my path ???

Last edited by sibal : November 4th, 2011 at 05:44 PM. Reason: Image was not showing

Reply With Quote
  #2  
Old November 9th, 2011, 06:36 AM
sr sr is offline
Problem Solver
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jan 2001
Location: Stockholm, Sweden
Posts: 4,434 sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level)sr User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 8 h 1 m 40 sec
Reputation Power: 532
Add PRIMARY KEY to the definition of the column:
Code:
ALTER TABLE  `mybb_posts` CHANGE  `pid`  `pid` INT( 10 ) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT



BTW:
1.
Are you sure that everything is perfect after this modification?
Couldn't you have more than one posts with the same subject if they are related to the same thread for example?

2.
If your plan was to rename the mybb_postsx tables later it won't work well.

A CREATE TABLE .. SELECT ... will not result in the same table structure as the original table. All indexes are lost etc.

You should instead export the table definition with SHOW CREATE TABLE ... and then change the table name and run it again to create the ...x tables.
Then you can use:
Code:
INSERT INTO [yourXTables] SELECT * FROM [yourOrigTables];

That way the table structure will be identical between the old and new tables. Then you can just do a rename on the tables to switch the new ones into place.

Good luck!
__________________
/Stefan

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > SQL problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap