Jump to content
  • 0
Sign in to follow this  
evilpuncker

check if column exists

Question

I'm not that good regarding SQL queries so I'm here to ask something like:

 

 

if column xxxx exists on login table { execute sql query to add that column } end; (pseudocode)

 

 

 

PS: I know how to check if table exists but I'm kinda confused to do the same with columns

Edited by evilpuncker

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

what if my user doesn't have access to syscolumns and sysobjects? :P I've seen several examples at google search but none worked :/ always syntax error :P I've seen a npc at old eA forum that did the same thing that I'm trying to do but sadly can't find it anymore :/

 

you are right  , there is  a more simple  way to check

 

if(query_sql ("select column from `table`"))

 dispbottom "exist";

else

 dispbottom "not exist";

}

Share this post


Link to post
Share on other sites
  • 0

You could use something with query_sql/query_logsql like:

 

 

query_sql("IF COL_LENGTH('table_name','column_name') IS NOT NULL BEGIN /*insert update query here*/ END");

Share this post


Link to post
Share on other sites
  • 0

if(query_sql("select count(name) from syscolumns where id=(select id from sysobjects where name='table name')and name='column name'")){


}else{


}
 

Share this post


Link to post
Share on other sites
  • 0

what if my user doesn't have access to syscolumns and sysobjects? :P I've seen several examples at google search but none worked :/ always syntax error :P I've seen a npc at old eA forum that did the same thing that I'm trying to do but sadly can't find it anymore :/

Share this post


Link to post
Share on other sites
  • 0

thanks my dear <3 but after creating the table it always throw an warning at map server

 

 

if(query_sql("select `stats` from `login`"))

 

 

 

[Warning]: script:query_sql: Too many columns, discarding last 1 columns.

Share this post


Link to post
Share on other sites
  • 0

thanks my dear <3 but after creating the table it always throw an warning at map server

 

 

if(query_sql("select `stats` from `login`"))

 

 

 

[Warning]: script:query_sql: Too many columns, discarding last 1 columns.

 

Haha ~ -_- ,  forgot to put array variable to save the select output

Edited by Angelmelody

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
Answer this question...

×   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.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.