tags:

views:

36

answers:

2

hey guys

i need to run this mysql code on my sites and i suspect some of them to have already this column

is there anything such if not exists for the bellow code ?!

ALTER TABLE `comments` 
    ADD COLUMN `active` int(1)   NOT NULL DEFAULT '0' after `sid`, 

im concerning this to prevent getting the duplicated column error !

+1  A: 

It's not built it but it can be accomplished using the information_schema database

http://www.cryer.co.uk/brian/mysql/howto_add_column_unless_exists.htm

bemace
A: 
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'tbl_name'
AND table_schema = 'db_name'
AND column_name = 'column_name'

should give you what you are looking for!!

InSane