我正在使用MySQL Workbench来创建和管理漫画书商店数据库。我在向COMIC_ISSUE表中插入行时遇到问题。我遇到的问题是同样的问题,许多其他人在这里发布的问题只是没有一个修复似乎对我有用。以下是有关COMIC_TITLE和COMIC_ISSUE表的信息。我列出了COMIC_TITLE表,因为'name'列是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)
以下是我尝试过的一些INSERT:
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
最后一个错误很有趣。我尝试插入一个空值(不允许),它抱怨该列不能为null,因此它显然看到了列。请注意,我已经尝试了许多不同的方法,例如“INSERT INTO COMIC_ISSUE”(即没有反引号而没有指定数据库。)我尝试列出所有列。我试着把'蝙蝠侠'放在双引号中,根本没有引号。什么都没做。任何建议都是最受欢迎的。
答案 0 :(得分:3)
我认为你的触发器会产生问题。所以试试这个......
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$$
在定义触发器时,两个关键字对于SQL语句是唯一的;旧的和新的。
这些关键字允许您在事件触发之前和之后引用数据。
检查一次......