I've created a stored procedure to change the column name as below.
Table structure:
CREATE TABLE ``procedurecheck`` (
``id`` int(10) NOT NULL AUTO_INCREMENT,
``colname`` varchar(50) NOT NULL,
``proccheck1`` varchar(50) NOT NULL,
PRIMARY KEY (``id``)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
This is a test code only to check procedures.
DELIMITER $$
CREATE PROCEDURE updateColumn(IN COLNAME varchar (50), IN NEWCOLNAME varchar (50))
BEGIN
SET @ddl = CONCAT('alter table procedurecheck CHANGE (', COLNAME, ' ', NEWCOLNAME, ' VARCHAR(50) NOT NULL)');
PREPARE STMT FROM @ddl;
EXECUTE STMT;
END $$
DELIMITER ;
When i call this function using:
CALL updateColumn('proccheck','newproccheck');
i get an error as follws:
#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 '(proccheck newproccheck VARCHAR(50) NOT NULL)' at line 1
Any pointers would be helpful.
Thanks