LoginSignup
juza11
@juza11

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

sqlでテーブルを作成するとき、syntaxエラーが出てしまう

Q&AClosed

解決したいこと

コマンドプロンプトにて、sqlでテーブルを作成したいのですが、下記の通りエラーが出てしまいます。
原因、対処法がわかる方教えていただきたいです。

発生している問題・エラー

ERROR 1064 (42000): 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 'current_timestamp
)' at line 9

例)

または、問題・エラーが起きている画像をここにドラッグアンドドロップ

該当するソースコード

mysql> create table cafe.contacts(
id int primary key auto_increment,
name varchar(50) not null,
kana varchar(50) not null,
tel varchar(11),
email varchar(100) not null,
body text,
create_at datetime current_timestamp
);

例)


自分で試したこと

ここに問題・エラーに対して試したことを記載してください。
以下のコマンドでも同様のエラーがでました。
create table cafe.contacts(
id int primary key,
name varchar(50) not null,
kana varchar(50) not null,
tel varchar(11),
email varchar(100) not null,
body text,
create_at datetime,
auto_increment(id),
current_timestamp(created_at)
);

また、以下のコマンドではテーブルが作成できました。
create table cafe.user (id int, name varchar(10));
Query OK, 0 rows affected (0.14 sec)

0

2Answer

下記を「id int AUTO_INCREMENT NOT NULL primary key,」にすることでエラー解消しませんか?

id int primary key auto_increment,

1Like

Comments

  1. @juza11

    Questioner

    ありがとうございます。

    アドバイスの通りやってみたのですが、同様のエラーが出てしまいました。
    「create_at datetime current_timestamp」
    の部分を

    「create_at datetime current_timestamp」
    にすると、テーブルは作成は作成できました。

ERROR 1064 (42000): 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 'current_timestamp
)' at line 9

defaultがないからでは?

- create_at datetime current_timestamp
+ create_at datetime default current_timestamp
1Like

Comments

  1. @juza11

    Questioner

    その通りでした。
    ありがとうございます。

Your answer might help someone💌