lordvader Posted May 15, 2008 Share Posted May 15, 2008 I want to add a column to an existing table, but first I have to check if the column exists. I can think of several ways to check: CASE WHEN EXISTS SHOW COLUMNS mysql_list_fields mysql_num_fields mysql_field_name But I was wondering in your experience, what is the simplest most efficient way to check if a column exists, if not, then add it to the table? thanks Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted May 16, 2008 Share Posted May 16, 2008 dynamic column adding isn't the strongest idea in databasing whats your motive behind it? Quote Link to comment Share on other sites More sharing options...
fenway Posted May 16, 2008 Share Posted May 16, 2008 You can use DESCRIBE TABLE, SHOW COLUMNS, or the I_S tables to query the schema, but there's no ADD IF EXISTS.. .you'll need to do it in 2 steps. But you'd better not be making dynamic column names... Quote Link to comment 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.