sql代码drop procedure if exists col_homework;
create procedure col_homework()
BEGIN  /*创建procedure*/
declare @string VARCHAR(100) CHARACTER SET gbk DEFAULT NULL;
/*声明declare*/
set @string = CONCAT('alter table' b.TABLE_NAME ' drop FOREIGN KEY' a.CONSTRAINT_NAME)from
 information_schema.REFERENTIAL_CONSTRAINTS a,information_schema.TABLES b 
WHERE a.TABLE_NAME=b.TABLE_NAME AND b.TABLE_SCHEMA = 'tschool';
EXECUTE(@string);
END
drop procedure if exists col_homework; 错误代码

解决方案 »

  1.   

    [Err] 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 '@string VARCHAR(100) CHARACTER SET gbk DEFAULT NULL;
      

  2.   

    错误太多 示例
    DELIMITER $
    DROP PROCEDURE IF EXISTS col_homework$
     CREATE PROCEDURE col_homework()
     BEGIN  
     DECLARE Astring CHAR(100) ;
     SET Astring=CONCAT('AA');
     SET @AA=Astring;
     PREPARE ASQL FROM @AA;
     EXECUTE ASQL;
     END$
     DROP PROCEDURE IF EXISTS col_homework$ 
    DELIMITER ;
      

  3.   

    什么玩意啊,copy的代码都能上
      

  4.   

    动态语句
    预编译才能执行的
    PREPARE   
    excutedrop procedure if exists col_homework;
    create procedure col_homework()
    BEGIN  /*创建procedure*/
    declare @string VARCHAR(100) CHARACTER SET gbk DEFAULT NULL;
    /*声明declare*/
    set @string = CONCAT('alter table' b.TABLE_NAME ' drop FOREIGN KEY' a.CONSTRAINT_NAME)from
     information_schema.REFERENTIAL_CONSTRAINTS a,information_schema.TABLES b 
    WHERE a.TABLE_NAME=b.TABLE_NAME AND b.TABLE_SCHEMA = 'tschool';
    PREPARE  stmt from @string;
    EXECUTE(@string);
    END;