是否有禁用插入表的机制? [英] Is there a mechanism to disable insert into table?

查看:46
本文介绍了是否有禁用插入表的机制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,它纯粹是用作某些逻辑的数组.

I have a table that is exists purely to serve as an array for some logic.

表格应该只有一行,否则我的逻辑就会失败.是否有任何 DDL 命令可以禁用插入表?

The table should have only one row otherwise my logic fails. Is there any DDL command to disable insert into table?

截至目前 - 我已经插入了我的逻辑所需的一行"数据,现在,计划创建一个插入后触发器来删除新输入的记录.乙)

As of now - I have inserted that 'one row' of data that is required for my logic, and now, plan to create an after insert trigger to delete the newly entered record. B)

但是我注意到有一些 ALTER TABLE 命令可以禁用/启用键,所以我想知道是否有替代触发代码的方法.

However I noticed that there were some ALTER TABLE commands to disable/ enable keys, so I was wondering if there is an alternative to the trigger code.

mysql> select version();
5.6.25-enterprise-commercial-advanced-log

推荐答案

这通常不是我们应该如何使用关系,但它可以用一个列来完成,该列可能只有一个值,但也有一个 UNIQUE KEY 覆盖它:

This is generally not how we're supposed to use relations, but it can be done with a column that may take on only one value, but which also has a UNIQUE KEY over it:

CREATE TABLE `MyTable` (
   `ActualData1` INT NOT NULL DEFAULT 0,
   `ActualData2` INT NOT NULL DEFAULT 0,
   `ActualData3` INT NOT NULL DEFAULT 0,

   `Dummy` ENUM("!") NOT NULL DEFAULT "!",
   UNIQUE KEY `OnlyOneRowAllowed` (`Dummy`)
);

…如果您不介意有一个额外的列,否则您将永远不会使用它.

…if you don't mind there being an additional column present that you're otherwise never going to use.

这篇关于是否有禁用插入表的机制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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