0

I have the following table:

CREATE TABLE Trans (
    tranID int NOT NULL AUTO_INCREMENT,
    tranDate datetime NOT NULL DEFAULT  CURDATE(),
    amount INT,
    account_number INT,
        FOREIGN KEY(account_number) REFERENCES Account(account_number) ON DELETE CASCADE,
    PRIMARY KEY(tranID)

);

and every time a trans happens the date is inserted so it has a timestamp. However, I am getting an issue when trying to implement it. I got the CURDATE example off the W3C schools website to make my life easier but I cannot seem to get it to work.

Softey
  • 1,451
  • 3
  • 21
  • 42
  • 1
    Are you sure you're not missing the `DEFAULT` keyword? – hjpotter92 Feb 26 '14 at 14:40
  • @hjpotter92 I had that in originally but took it out to see if it would change anything. I have put it back in now. THank you – Softey Feb 26 '14 at 14:42
  • possible duplicate of [Create table fail in mysql when using CURDATE() as default](http://stackoverflow.com/questions/3696778/create-table-fail-in-mysql-when-using-curdate-as-default) – hjpotter92 Feb 26 '14 at 14:44
  • 1
    try using CURRENT_TIMESTAMP instead – avisheks Feb 26 '14 at 14:46
  • possible duplicate of [How do you set a default value for a MySQL Datetime column?](http://stackoverflow.com/questions/168736/how-do-you-set-a-default-value-for-a-mysql-datetime-column) – fancyPants Feb 26 '14 at 14:47

1 Answers1

4

try this

CREATE TABLE `test`.`temp` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `dateTime` DATETIME NULL DEFAULT NOW(),
  PRIMARY KEY (`id`));
Bjego
  • 665
  • 5
  • 14