2012-01-06 97 views
0

SQL查詢:想不通爲什麼這個sql查詢不工作

CREATE TABLE mytbl.customer(
CustID int(10) NOT NULL AUTO_INCREMENT , 
FirstName varchar(40) , 
LastName varchar(40) , 
Street varchar(50) , 
City varchar(40) , 
State varchar(40) , 
ZipCode varchar(5) , 
Telephone varchar(20) , 
CellPhone varchar(20) , 
CellCarrier varchar(20) , 
UserName varchar(20) , 
PASSWORD varchar(10) , 
SecretQuestion varchar(80) , 
SecretAnswer varchar(50) , 
UtilityCompanyID int(10) , 
SwUpgrade int(10) DEFAULT 1, 
DateToSignIn timestamp DEFAULT 0000 -00 -0000 :00 :00 NOT NULL , 
LastLoginTime timestamp DEFAULT 0000 -00 -0000 :00 :00 NOT NULL , 
STATUS varchar(20) DEFAULT 'Inacitve', 
Email1 varchar(60) , 
Email2 varchar(60) , 
PoolID int(10) , 
DeviceID int(10) , 
Last_Modified_Timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL , 
PRIMARY KEY (CustID) 
) ENGINE = InnoDB DEFAULT CHARSET = latin1; 

phpMyAdmin的錯誤:

#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 '-00-00 00:00:00 NOT NULL, 
    LastLoginTime timestamp DEFAULT 0000-00-00 00:00:00 ' at line 18 

任何想法,我可能是做錯了?

+0

沒有檢查時間戳創建字段看起來不對 - 你確定這些工作? DateToSignIn時間戳DEFAULT 0000 -00 -0000:00:00 NOT NULL, LastLoginTime時間戳DEFAULT 0000 -00 -0000:00:00 NOT NULL, – 2012-01-06 05:30:47

回答

2

不應該將這些時間戳的默認值放在「」,即「0000-00-00 00:00:00」嗎?

1

您的默認時間戳值應該是這樣的。

DEFAULT '0000-00-00 00:00:00' NOT NULL 
0

不知道你在哪裏得到了默認的構造,但嘗試:

LastLoginTime timestamp DEFAULT '0000-00-00 00:00:00' 
0

manual

If a DEFAULT value is specified for the first TIMESTAMP column in a table, it is not ignored. The default can be CURRENT_TIMESTAMP or a constant date and time value.

To specify automatic default or updating for a TIMESTAMP column other than the first one, you must suppress the automatic initialization and update behaviors for the first TIMESTAMP column by explicitly assigning it a constant DEFAULT value

工作查詢

CREATE TABLE mytbl.customer(
CustID int(10) NOT NULL AUTO_INCREMENT , 
FirstName varchar(40) , 
LastName varchar(40) , 
Street varchar(50) , 
City varchar(40) , 
State varchar(40) , 
ZipCode varchar(5) , 
Telephone varchar(20) , 
CellPhone varchar(20) , 
CellCarrier varchar(20) , 
UserName varchar(20) , 
PASSWORD varchar(10) , 
SecretQuestion varchar(80) , 
SecretAnswer varchar(50) , 
UtilityCompanyID int(10) , 
SwUpgrade int(10) DEFAULT 1, 
DateToSignIn timestamp DEFAULT 0 , 
LastLoginTime timestamp DEFAULT 0, 
STATUS varchar(20) DEFAULT 'Inacitve', 
Email1 varchar(60) , 
Email2 varchar(60) , 
PoolID int(10) , 
DeviceID int(10) , 
Last_Modified_Timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL , 
PRIMARY KEY (CustID) 
) ENGINE = InnoDB DEFAULT CHARSET = latin1 
0

指定自動默認或更新比第一個以外的TIMESTAMP列,你必須明確地分配一個不變的缺省值抑制了第一個TIMESTAMP列自動初始化和更新的行爲(例如,DEFAULT 0DEFAULT'2003-01-01 00:00:00')。然後,對於另一個TIMESTAMP列,規則與第一個TIMESTAMP列相同,只是如果省略DEFAULT和ON UPDATE子句,則不會進行自動初始化或更新。

SOURCE

相關問題