Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a sql query
SQL
delimiter '$$'
DROP PROCEDURE IF Exists addcol $$

CREATE PROCEDURE addcol() BEGIN
IF NOT EXISTS ( (
	SELECT * FROM information_schema.COLUMNS
	WHERE COLUMN_NAME='newcol' AND TABLE_NAME='pp_tbl1' AND TABLE_SCHEMA='mydb'
	) )	THEN 
	ALTER TABLE `mydb`.`pp_tbl1` ADD COLUMN `newcol` bit  NOT NULL default 0;
END IF;
END$$
delimiter ';'
CALL addcol();
DROP PROCEDURE addcol;


previously i added a column 'newcol' but deleted it using Navicat gui and then ran this query
but it is giving me 0 rows effected
when i execute this query

SQL
SELECT * FROM information_schema.COLUMNS
	WHERE COLUMN_NAME='newcol' AND TABLE_NAME='pp_tbl1' AND TABLE_SCHEMA='mydb'


it is giving me result but i cannot find the column in my table

i am using mysql 5.1

also check the below query which is not working correct if possible

SQL
delimiter ';;'
create procedure foo ()
begin
    declare continue handler for 1060 begin end;
    alter table `pp_tbl1` add `newcol` bit  NOT NULL default 0;
end;;
call foo();;
Posted
Updated 27-Feb-13 1:00am
v2

1 solution

Your Alter Table Query is Wrong.
Key word Column should not be there.

Correct query is as follows.

ALTER TABLE `mydb`.`pp_tbl1` ADD `newcol` bit  NOT NULL default 0;
 
Share this answer
 
Comments
agha_ali22 27-Feb-13 5:42am    
but issue is same as above

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900