2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

DB H2でuser テーブルを作成する方法

Posted at

問題

H2 DB使用時に文法エラーが発生し、userテーブルを作成できない。

CREATE TABLE user (ID INT PRIMARY KEY,  NAME VARCHAR(255));
SQLステートメントに文法エラーがあります "CREATE TABLE [*]user (ID INT PRIMARY KEY,  NAME VARCHAR(255))"; 期待されるステートメント "identifier"
Syntax error in SQL statement "CREATE TABLE [*]user (ID INT PRIMARY KEY,  NAME VARCHAR(255))"; expected "identifier"; SQL statement:
CREATE TABLE user (ID INT PRIMARY KEY,  NAME VARCHAR(255)) [42001-214] 42001/42001

調べたところ、userはSQLの予約語であり、テーブル名に使用できないことが分かった。

解決方法

userをダブルクオテーションで囲む

CREATE TABLE "user" (ID INT PRIMARY KEY,  NAME VARCHAR(255));
更新数: 0
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?