Search code examples
alter-tablesinglestore

MemSql > add column if does not exist


I didn't find anything in documentation regarding this part - add column to table if not exist or check if column exists.

Although there is a way to see the description of a table, but it would be nice to check it right in SQL query.

Any ideas how to do at least on of these?


Solution

  • You can check if a column exists in SQL by querying information_schema.columns and seeing if it is present there - e.g.

    select count(*) from information_schema.columns where table_name = 't' and column_name = 'c'
    

    You can add a column with ALTER TABLE ADD COLUMN.