MySQL error in timestamp

本小妞迷上赌 提交于 2020-06-29 10:16:25

问题


I am creating a database for my application. I get this error: MySQL said: Documentation

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 '(14) NOT NULL,

  PRIMARY KEY  (UserID))' at line 4 .

This is my sql statement:

CREATE TABLE sitheloChat_Users (
  UserID int(10) unsigned NOT NULL auto_increment,
  Username varchar(15) NOT NULL default '',
  PreviousUpdate timestamp(14) NOT NULL,
  PRIMARY KEY  (UserID)
);

What must i add or edit?


回答1:


Remove the (14) from timestamp

 mysql> CREATE TABLE sitheloChat_Users 
( UserID int(10) unsigned NOT NULL auto_increment,
 Username varchar(15) NOT NULL default '', 
PreviousUpdate timestamp NOT NULL, PRIMARY KEY (UserID) );
    Query OK, 0 rows affected (0.03 sec)



回答2:


TimeStamp doesn't need the length like String (varchar/varchar2).

CREATE TABLE sitheloChat_Users ( UserID int(10) unsigned NOT NULL auto_increment,
Username varchar(15) NOT NULL default '', PreviousUpdate timestamp NOT NULL, 
PRIMARY KEY (UserID) );


来源:https://stackoverflow.com/questions/11362655/mysql-error-in-timestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!