gpt4 book ai didi

mysql - 是否有可能模仿或鬼化一张 table ?

转载 作者:行者123 更新时间:2023-11-29 12:13:08 25 4
gpt4 key购买 nike

所以情况是我有一些使用数据库表的代码,我想我可以用另一个表中的 View 替换该表。

我可能会重命名/删除现有表,然后以某种方式创建一个复制该表的 View ,以便 php 代码认为它正在使用该表。

也许我应该做的是创建 View ,然后简单地查找并替换代码中表名称的所有实例?

模仿或鬼化 table 的最佳方法是什么?

最佳答案

将表重命名为

 RENAME TABLE <table_name> TO <new_table_name>;

然后创建与原始table_name同名的 View 。当从表中读取数据时,您的 PHP 代码将继续正常工作,无需再担心。如果您的代码还必须更新、删除或插入该 View ,则存在某些限制。

There must be a one-to-one relationship between the rows in the view and the rows in the underlying table. There are also certain other constructs that make a view nonupdatable. To be more specific, a view is not updatable if it contains any of the following:

  • Aggregate functions (SUM(), MIN(), MAX(), COUNT(), and so forth)

  • DISTINCT

  • GROUP BY

  • HAVING

  • UNION or UNION ALL

  • Subquery in the select list

  • Certain joins (see additional join discussion later in this section)

  • Reference to nonupdatable view in the FROM clause

  • Subquery in the WHERE clause that refers to a table in the FROM clause

  • Refers only to literal values (in this case, there is no underlying table to update)

  • ALGORITHM = TEMPTABLE (use of a temporary table always makes a view nonupdatable)

  • Multiple references to any column of a base table

manual 中了解更多相关信息.

关于mysql - 是否有可能模仿或鬼化一张 table ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30317491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com