2014-04-03 115 views
0
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。錯誤CREATE TABLE MYSQL:語法

回答

1
pf_date timestamp(14) NOT NULL, 

pf_date timestamp NOT NULL, 

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)) ; 

您在第一個create語句中也有錯誤的鍵名稱。

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

+2

謝謝,但我仍然得到一個錯誤:#1064 - 你有一個錯誤的SQL語法; (14)NOT NULL, pf_status int(1)DEFAULT 0 NOT NULL, PRIMARY KEY(p'在第8行) –

+1

@RafedNole,don '不喜歡這樣,我會找到正確的答案,那麼你爲什麼喜歡在這篇文章中打出答案 – jmail

+0

@jmail我不認爲你確實發現了錯誤的關鍵名稱的問題!!但是,對於我的知識,我已經upvoted你的回答!! CHEK我的最後一次編輯完成時 –

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

+0

看看我的回答 – jmail

+0

寫int(14)有什麼不對嗎? –

+1

是的,這是錯誤的格式,你應該重新考慮這些想法,因爲時間戳顯示時間和日期,所以不要給'長度' – jmail