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);
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);
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()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us