我创建了以下存储过程。但它给出了语法错误。我无法指出问题所在。
DELIMITER |
CREATE PROCEDURE createtables()
BEGIN
CREATE DATABASE test;
USE test;
CREATE TABLE employee(eid int PRIMARY KEY, ename varchar(45));
CREATE TABLE account(accid int PRIMARY KEY, amount float);
CREATE TABLE department(dip int PRIMARY KEY, depname varchar(45), eid int, FOREIGN KEY(dip) REFERENCES employee(eid));
END |
DELIMITER ;
答案 0 :(得分:1)
我认为你不能在存储过程中使用USE
。所以请尝试:
DELIMITER |
CREATE PROCEDURE createtables()
BEGIN
CREATE DATABASE test;
CREATE TABLE test.employee(eid int PRIMARY KEY, ename varchar(45));
CREATE TABLE test.account(accid int PRIMARY KEY, amount float);
CREATE TABLE test.department(dip int PRIMARY KEY, depname varchar(45), eid int, FOREIGN KEY(dip) REFERENCES test.employee(eid));
END |
DELIMITER ;