0

I'm creating a new table after starting MySQL service.

I code it at Win10, on MySQL 8.0 command line Client. The code now is shown as below:

create table 't8' ('id1' timestamp not null default current_timestamp,'id2' datetime default null);

Then I got an error while I was executing it:

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 ''t8' ('id1' timestamp not null default current_timestamp,'id2' datetime defaul' at line 1

What should I do to fix it?

halfer
  • 19,824
  • 17
  • 99
  • 186
Eve Liu
  • 3
  • 1

2 Answers2

0

Use it like this.

create table t8 (
    `id1` timestamp not null default current_timestamp,
    `id2` datetime default null
);
Bilal Ahmed
  • 119
  • 1
  • 11
  • Because table and column names are not meant to define with single quote notation, because according to sql code syntax the way to define table and columns is this ` You can check in phpmyadmin or any other tool to generate any query like create update or delete. – Bilal Ahmed Sep 27 '19 at 07:18
0

Try below - instead of single quote '' you need to use back tick `` or you can keep it just id1 or id2

create table t8
(
  id1 timestamp not null default current_timestamp,
  id2 datetime null
)
Fahmi
  • 37,315
  • 5
  • 22
  • 31