在H2 Webserver中创建数据库表失败,出现语法错误

时间:2017-10-23 14:59:24

标签: java sql h2

我使用H2数据库引擎通过Eclipse创建了一个Web服务器:

我的代码:

Server server = Server.createTcpServer("-tcp","-tcpAllowOthers","-tcpPort","9092").start();
Server webServer = Server.createWebServer("-web","-webAllowOthers","-webPort","8082").start();

然后我通过我的网址访问它并想要做一些SQL-Stuff。所以我试着创建几个表:

DROP TABLE IF EXISTS RATING;
DROP TABLE IF EXISTS FILM;
DROP TABLE IF EXISTS USER;
CREATE TABLE FILM (
   FILMID INT PRIMARY KEY,
   TITLE VARCHAR(255)
);
CREATE TABLE USER (
   MAIL VARCHAR(255) PRIMARY KEY,
   TITLE VARCHAR(255),
   LASTNAME VARCHAR(255),
   FIRSTNAME VARCHAR(255)
);
CREATE TABLE RATING (
   FILM_FILMID INT,
   USER_MAIL VARCHAR(255),
   RATING INT,
   FOREIGN KEY (FILM_FILMID) REFERENCES (FILM.FILMID),
   FOREIGN KEY (USER_MAIL) REFERENCES (USER.MAIL),
   PRIMARY KEY (FILM_FILMID, USER_MAIL)
);

问题是,只创建了两个表:FILMUSER,但未评级。

控制台输出:

DROP TABLE IF EXISTS RATING;
Änderungen: 0
(1 ms)

DROP TABLE IF EXISTS FILM;
Änderungen: 0
(2 ms)

DROP TABLE IF EXISTS USER;
Änderungen: 0
(1 ms)

CREATE TABLE FILM ( 
   FILMID INT PRIMARY KEY, 
   TITLE VARCHAR(255) 
);
Änderungen: 0
(1 ms)

CREATE TABLE USER ( 
   MAIL VARCHAR(255) PRIMARY KEY, 
   TITLE VARCHAR(255), 
   LASTNAME VARCHAR(255), 
   FIRSTNAME VARCHAR(255) 
);
Änderungen: 0
(1 ms)

CREATE TABLE RATING ( 
   FILM_FILMID INT, 
   USER_MAIL VARCHAR(255), 
   RATING INT, 
   FOREIGN KEY (FILM_FILMID) REFERENCES (FILM.FILMID), 
   FOREIGN KEY (USER_MAIL) REFERENCES (USER.MAIL), 
   PRIMARY KEY (FILM_FILMID, USER_MAIL) 
);
Syntax Fehler in SQL Befehl "CREATE TABLE RATING ( 
   FILM_FILMID INT, 
   USER_MAIL VARCHAR(255), 
   RATING INT, 
   FOREIGN KEY (FILM_FILMID) REFERENCES (FILM.[*]FILMID), 
   FOREIGN KEY (USER_MAIL) REFERENCES (USER.MAIL), 
   PRIMARY KEY (FILM_FILMID, USER_MAIL) 
)"; erwartet "ASC, DESC, NULLS, ,, )"
Syntax error in SQL statement "CREATE TABLE RATING ( 
   FILM_FILMID INT, 
   USER_MAIL VARCHAR(255), 
   RATING INT, 
   FOREIGN KEY (FILM_FILMID) REFERENCES (FILM.[*]FILMID), 
   FOREIGN KEY (USER_MAIL) REFERENCES (USER.MAIL), 
   PRIMARY KEY (FILM_FILMID, USER_MAIL) 
)"; expected "ASC, DESC, NULLS, ,, )"; SQL statement:
CREATE TABLE RATING ( 
   FILM_FILMID INT, 
   USER_MAIL VARCHAR(255), 
   RATING INT, 
   FOREIGN KEY (FILM_FILMID) REFERENCES (FILM.FILMID), 
   FOREIGN KEY (USER_MAIL) REFERENCES (USER.MAIL), 
   PRIMARY KEY (FILM_FILMID, USER_MAIL) 
) [42001-196] 42001/42001

代码有什么问题?我真的不明白输出要告诉我什么,我找不到任何语法问题。

0 个答案:

没有答案