MySQL エラー「Error Code: 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 ‘-xxx’ at line 1」が発生した場合の対処法

MySQLで、エラー「Error Code: 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 ‘-xxx’ at line 1」が発生した場合の対処法を記述してます。
環境
- OS ubuntu21.10
- MySQL Ver 8.0.27-0ubuntu0.21.10.1 for Linux on x86_64 ((Ubuntu))
- MySQL Workbench 8.0.27
エラー全文
以下のクエリを実行時に発生。
create table new-table(
id int
);
エラー全文
create table new-table( id int )
Error Code: 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 '-table( id int )' at line 1
原因
テーブル名に「-(ハイフン)」が含まれているため
対処法
テーブル名を「`(バッククウォート)」で囲ってあげる
create table `new-table`(
id int
);
-
前の記事
javascript 型を取得する 2022.03.28
-
次の記事
コマンドプロンプトのタイトルを変更する 2022.03.28
コメントを書く