Author Topic: Query - ALTER TABLE  (Read 446 times)

0 Members and 1 Guest are viewing this topic.

Offline karimali831Topic starter

  • Enthusiast
  • Posts: 379
    • View Profile
Query - ALTER TABLE
« on: June 13, 2010, 04:19:36 PM »
Hi,

When I use the below query:
Code: [Select]
mysql_query("ALTER TABLE `".PREFIX."settings`
    ADD `col2` INT(11) NOT NULL default '1' AFTER `col1`,
    ADD `col3` varchar(255) NOT NULL default 'irc.evolu.net' AFTER `col2`;")
OR die(PREFIX.'settings failed');

It will die even though I have col2 but not col3 (column)
So lets say I have column col2 and not column col3, how can I change the query to that it will add column 3 only?
So basically add what I don't have and never mind the columns that are already there.

Thanks for help

Offline karimali831Topic starter

  • Enthusiast
  • Posts: 379
    • View Profile
Re: Query - ALTER TABLE
« Reply #1 on: June 13, 2010, 06:50:08 PM »
no? you can not do this?

Offline karimali831Topic starter

  • Enthusiast
  • Posts: 379
    • View Profile
Re: Query - ALTER TABLE
« Reply #2 on: June 14, 2010, 02:39:01 PM »
 >:(

Offline karimali831Topic starter

  • Enthusiast
  • Posts: 379
    • View Profile
Re: Query - ALTER TABLE
« Reply #3 on: June 14, 2010, 03:39:18 PM »
 :-\

Offline Soldier Jane

  • Irregular
  • Posts: 29
    • View Profile
Re: Query - ALTER TABLE
« Reply #4 on: June 15, 2010, 03:34:41 AM »
I've yet to learn properly how to do this, but I'm guessing it's something like:

mysql_query("ALTER tablename ADD col3 varchar (255) NOT NULL default 'irc.evolu.net' AFTER col2");

Might be a couple of mistakes in there but it's along the right lines at least.

Offline Illusion

  • Enthusiast
  • Posts: 330
  • Gender: Male
    • View Profile
Re: Query - ALTER TABLE
« Reply #5 on: June 15, 2010, 07:06:51 AM »
You want to have all that intelligence in single query, I think that's not possible.
"Free as in freedom, not beer."

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,443
  • Gender: Male
    • View Profile
Re: Query - ALTER TABLE
« Reply #6 on: June 16, 2010, 11:05:45 AM »
Why would you even want to?
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.