Answers for "alter table if not exists column"

SQL
-1

add column if not exists

ALTER TABLE test ADD COLUMN IF NOT EXISTS column_a VARCHAR(255);
ALTER TABLE test MODIFY IF EXISTS column_a VARCHAR(255);
Posted by: Guest on April-15-2021
0

how to check if a column exists before alter the table

conn = sqlite3.connect(':memory:')
c = conn.cursor()
try:
    c.execute('ALTER TABLE mytable ADD COLUMN newcolumn;')
except:
    pass # handle the error
c.close()
Posted by: Guest on August-18-2021

Code answers related to "alter table if not exists column"

Code answers related to "SQL"

Browse Popular Code Answers by Language