CREATE TABLE MYSQL中的错误:语法

时间:2014-04-03 13:29:25

标签: mysql web database-administration

  CREATE TABLE IF NOT EXISTS `pforum` 

( 
    pf_id int(10) NOT NULL auto_increment, 
    pf_name varchar(50) NOT NULL, 
    pf_title varchar(255) NOT NULL, 
    pf_ppost varchar(1000) NOT NULL, 
    pf_aud varchar(20) NOT NULL, 
    pf_username varchar(20) NOT NULL, 
    pf_date timestamp(14) NOT NULL, 
    pf_status  int(1) DEFAULT 0 NOT NULL, 
    PRIMARY KEY (pr_id) 

    )  ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

    CREATE TABLE IF NOT EXISTS `p_reset`
( 
     pr_id int(10) NOT NULL auto_increment, 
     pr_name varchar(50) NOT NULL, 
     pr_email varchar(255) NOT NULL, 
     pr_dob varchar(20) NOT NULL, 
     pr_roll varchar(20) NOT NULL, 
     pr_date timestamp(14) NOT NULL, 
     pr_status int(1) DEFAULT 0 NOT NULL, 
     PRIMARY KEY (pr_id) ) ;

我检查了可能的原因但我仍然收到错误1064。

2 个答案:

答案 0 :(得分:1)

pf_date timestamp(14) NOT NULL, 

pf_date timestamp  NOT NULL, 

pr_date timestamp(14) NOT NULL, 

pr_date timestamp  NOT NULL, 

HEre是正确的

CREATE TABLE IF NOT EXISTS `pforum` 

( 
    pf_id int(10) NOT NULL auto_increment, 
    pf_name varchar(50) NOT NULL, 
    pf_title varchar(255) NOT NULL, 
    pf_ppost varchar(1000) NOT NULL, 
    pf_aud varchar(20) NOT NULL, 
    pf_username varchar(20) NOT NULL, 
    pf_date timestamp  NOT NULL, 
    pf_status  int(1) DEFAULT 0 NOT NULL, 
    PRIMARY KEY (pf_id) 

    )  ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

    CREATE TABLE IF NOT EXISTS `p_reset`
( 
     pr_id int(10) NOT NULL auto_increment, 
     pr_name varchar(50) NOT NULL, 
     pr_email varchar(255) NOT NULL, 
     pr_dob varchar(20) NOT NULL, 
     pr_roll varchar(20) NOT NULL, 
     pr_date timestamp NOT NULL, 
     pr_status int(1) DEFAULT 0 NOT NULL, 
     PRIMARY KEY (pr_id) ) ;

第一个create语句中也有一个错误的键名。

http://sqlfiddle.com/#!2/dd3e4f/1

答案 1 :(得分:1)

你应该删除长度值:timestamp

 pr_date timestamp(14) NOT NULL, 

喜欢改变:

 pr_date timestamp NOT NULL, 

看起来像你的完整代码:

CREATE TABLE IF NOT EXISTS `pforum` 

( 
    pf_id int(10) NOT NULL auto_increment, 
    pf_name varchar(50) NOT NULL, 
    pf_title varchar(255) NOT NULL, 
    pf_ppost varchar(1000) NOT NULL, 
    pf_aud varchar(20) NOT NULL, 
    pf_username varchar(20) NOT NULL, 
    pf_date timestamp  NOT NULL, 
    pf_status  int(1) DEFAULT 0 NOT NULL, 
    PRIMARY KEY (pf_id) 

    )  ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

    CREATE TABLE IF NOT EXISTS `p_reset`
( 
     pr_id int(10) NOT NULL auto_increment, 
     pr_name varchar(50) NOT NULL, 
     pr_email varchar(255) NOT NULL, 
     pr_dob varchar(20) NOT NULL, 
     pr_roll varchar(20) NOT NULL, 
     pr_date timestamp NOT NULL, 
     pr_status int(1) DEFAULT 0 NOT NULL, 
     PRIMARY KEY (pr_id) ) ;

http://dev.mysql.com/doc/refman/5.5/en/datetime.html