触发器不起作用 - 在插入之前更改表以添加新列 [英] Trigger Does not works - Alter table to add a new column before inserting in it

查看:60
本文介绍了触发器不起作用 - 在插入之前更改表以添加新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个触发器来更改一个表,该表向其中添加一个新列并在其中插入值.

I am making a trigger to alter a table that adds a new column to it and inserts the value in it.

我的代码看起来很糟糕:

My code looks lyk dis:

 delimiter |

 CREATE TRIGGER addfield AFTER INSERT ON `entity_group_mapping`
 FOR EACH ROW BEGIN
     ALTER TABLE user_access ADD NEW.type_name INT(2) NOT NULL;
 END;

 |
 delimiter ;

它给了我一个错误:#1103 - 不正确的表名 'NEW'

推荐答案

来自文档:

每个表有 4096 列的硬限制...每个表(无论存储引擎如何)的最大行大小为 65,535 字节.

你能达到这些限制吗?即使您不能,我建议您考虑设计,并添加记录而不是新字段.然后您可以尝试 PIVOT 表 - 将行转换为字段,互联网上有许多数据透视示例,当然还有 stackoverflow.

Can you reach these limitations? Even if you cannot, I'd suggest you to think about design, and add records instead of new fields. Then you could try to PIVOT table - translate rows into fields, there are many pivot examples in the internet and of course in stackoverflow.

这篇关于触发器不起作用 - 在插入之前更改表以添加新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆