View Single Post

   
  #3 (permalink)  
Old 02-28-2008, 07:36 AM
Ted
 
Posts: n/a
Default Re: Trouble creating triggers

This is a day for weird behaviour. I see my note appearing three times
now, and yet I got error messages from the server two times saying it
hadn't been posted.

Anyway, thanks Bill.

The errors I encountered, then, must be something odd in how MySQL
Query Browser handles this. When I do to the command line, and use the
client app. "mysql", the code is accepted and seems to work. However,
I get errors on the INSERT.

I set up a couple dummy tables in the test DB, and populated dummy with
three records.

dummy2 has two columns:dummy_id and name.

dummy has three columns, two identical to dummy2, and the third is
mydate

mysql> INSERT INTO dummy SELECT name FROM dummy2;
ERROR 1136 (21S01): Column count doesn't match value count at row 1

I get the same error if I use "SELECT * FROM dummy2" as my SELECT
clause.

This should have worked, I think, because dummy_id is autoincremented
in both tables. Adding dummy_id to the SELECT clause changed nothing.
I still get the same error. Why?

And while the automated timestamp updating built into MySQL looks
appealing, it too give me trouble, as the following copy of my code and
resultant output shows.

mysql> CREATE TABLE `test`.`dumm3` (
-> `dummy_id` INTEGER UNSIGNED NOT NULL DEFAULT 0,
-> `name` VARCHAR(45) NOT NULL DEFAULT '',
-> `mydate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
-> PRIMARY KEY(`dummy_id`)
-> )
-> ENGINE = InnoDB;
ERROR 1067 (42000): Invalid default value for 'mydate'
mysql> CREATE TABLE `test`.`dumm3` (
-> `dummy_id` INTEGER UNSIGNED NOT NULL DEFAULT 0,
-> `name` VARCHAR(45) NOT NULL DEFAULT '',
-> `mydate` DATETIME NOT NULL DEFAULT NOW(),
-> PRIMARY KEY(`dummy_id`)
-> )
-> ENGINE = InnoDB;
ERROR 1067 (42000): Invalid default value for 'mydate'
mysql> CREATE TABLE `test`.`dumm3` (
-> `dummy_id` INTEGER UNSIGNED NOT NULL DEFAULT 0,
-> `name` VARCHAR(45) NOT NULL DEFAULT '',
-> `mydate` DATETIME DEFAULT CURRENT_TIMESTAMP,
-> PRIMARY KEY(`dummy_id`)
-> )
-> ENGINE = InnoDB;
ERROR 1067 (42000): Invalid default value for 'mydate'

What have I missed?

Thanks,

Ted

Reply With Quote