Jump to content

check if columns exist befor alter


drisate

Recommended Posts

Hey guys!

I need to check if a columns exist before permorming a table alteration, This is what i got so fare:

 

IF NOT EXISTS (

SELECT * 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = `page` 
AND COLUMN_NAME = `aaa` 
)
BEGIN ALTER TABLE `page` ADD `aaa` LONGTEXT NOT NULL END 

 

The MySQL error it returns is:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = `pag' at line 1

Link to comment
https://forums.phpfreaks.com/topic/191662-check-if-columns-exist-befor-alter/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.