Question

I'm using MySQL Workbench to create and manage a comic book store database. I'm having a problem inserting rows into the COMIC_ISSUE table. The problem I'm having is the same problem many others posted questions about here only none of the fixes seem to be working for me. Here is information on the COMIC_TITLE and COMIC_ISSUE tables. I list the COMIC_TITLE table because the 'name' column is part of the composite primary key in the COMIC_ISSUE.

mysql> describe comic_title;
 +-------------------+-------------+------+-----+---------+-------+
 | Field             | Type        | Null | Key | Default | Extra |
 +-------------------+-------------+------+-----+---------+-------+
 | name              | varchar(45) | NO   | PRI | NULL    |       |
 | CREATOR_creatorID | int(11)     | NO   | PRI | NULL    |       |
 | isActive          | tinyint(1)  | NO   |     | 1       |       |
 +-------------------+-------------+------+-----+---------+-------+
 3 rows in set (0.01 sec)

mysql> select * from comic_title;
+----------+-------------------+----------+
| name     | CREATOR_creatorID | isActive |
+----------+-------------------+----------+
| Avengers |                 1 |        1 |
| Batman   |                 2 |        1 |
| Ironman  |                 3 |        1 |
+----------+-------------------+----------+
3 rows in set (0.00 sec)

mysql> describe comic_issue;
+-----------------------+--------------+------+-----+---------+-------+
| Field                 | Type         | Null | Key | Default | Extra |
+-----------------------+--------------+------+-----+---------+-------+
| COMIC_TITLE_name      | varchar(45)  | NO   | PRI | NULL    |       |
| volumeNum             | int(11)      | NO   | PRI | NULL    |       |
| coverDate             | date         | NO   | PRI | NULL    |       |
| PUBLISHER_publisherID | int(11)      | NO   | MUL | NULL    |       |
| inventoryQty          | int(11)      | NO   |     | NULL    |       |
| coverPrice            | decimal(4,2) | NO   |     | NULL    |       |
| issueTitle            | varchar(45)  | YES  |     | NULL    |       |
| synopsis              | longtext     | YES  |     | NULL    |       |
| format                | varchar(45)  | YES  |     | NULL    |       |
| storyArc              | varchar(45)  | YES  |     | NULL    |       |
+-----------------------+--------------+------+-----+---------+-------+
10 rows in set (0.00 sec)

Here are some INSERTs I've tried:

mysql> INSERT INTO `cbdb`.`COMIC_ISSUE` VALUES ('Batman', 1, '2011-11-01', (SELECT PublisherID from PUBLISHER where name = 'Marvel'), 100, 2.99, 'The New 52!', NULL, NULL, 'Court of Owls');

ERROR 1054 (42S22): Unknown column 'COMIC_TITLE_name' in 'field list'

mysql> INSERT INTO COMIC_ISSUE VALUES ('Ironman', 10, '2013-05-15', (SELECT PublisherID from PUBLISHER where name = 'Marvel'), 100, 3.99, 'The secret origin of Tony Stark', NULL, NULL, 'The secret origin of Tony Stark');

ERROR 1054 (42S22): Unknown column 'COMIC_TITLE_name' in 'field list'

mysql> INSERT INTO `cbdb`.`COMIC_ISSUE` VALUES (NULL, 1, '2011-11-01', (SELECT PublisherID from PUBLISHER where name = 'Marvel'), 100, 2.99, 'The New 52!', NULL, NULL, 'Court of Owls');

ERROR 1048 (23000): Column 'COMIC_TITLE_name' cannot be null

This last error was interesting. I tried inserting a null value (not allowed) and it complained that the column can't be null so it obviously sees the column. Please note that I've tried this a number of different ways, like "INSERT INTO COMIC_ISSUE" (i.e. without the backticks and without specifying the database.) I tried listing all the columns. I tried putting 'Batman' in double-quotes and no quotes at all. Nothing is doing it. Any suggestions are most welcome.

Was it helpful?

Solution

I Think your trigger creates problem.So try this one..

CREATE TRIGGER `update_mailbox` AFTER INSERT ON COMIC_ISSUE
FOR EACH ROW 
begin
INSERT INTO MAILBOX_has_COMIC_ISSUE VALUES ((SELECT MAILBOX_mailboxID FROM
MAILBOX_has_COMIC_TITLE WHERE
MAILBOX_has_COMIC_TITLE.COMIC_TITLE_name = new.COMIC_TITLE_name),
(SELECT MAILBOX_CUSTOMER_customerID FROM MAILBOX_has_COMIC_TITLE WHERE
MAILBOX_has_COMIC_TITLE.COMIC_TITLE_name = new.COMIC_TITLE_name), 
new.COMIC_TITLE_name, new.volumeNum,new.coverDate); end$$

Two keywords are unique to SQL statements while defining triggers i.e; OLD and NEW.

These keywords allow you to refer the data before and after the event triggers.

Check this once...

http://www.w3resource.com/mysql/mysql-triggers.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top