drisate Posted February 10, 2010 Share Posted February 10, 2010 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 More sharing options...
fenway Posted February 16, 2010 Share Posted February 16, 2010 Well, you can't start with IF... but why bother? Link to comment https://forums.phpfreaks.com/topic/191662-check-if-columns-exist-befor-alter/#findComment-1013134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.