dousi5501 2014-04-18 10:13
浏览 45

MySQL - 一次向所有查询添加常见的WHERE条件。

I have set of sql queries already written and working fine in my website.

Now, i want to add 'where common condition clause' all of those queries. I don't wanna re write all my queries with this additional condition, instead i like do something by which it automatically applies to all queries run on my database from now on.

Is there any such method to do this?

MY Data base: MYSQL

MY website: PHP, YII

  • 写回答

4条回答 默认 最新

  • douyue5856 2014-04-18 10:17
    关注

    There may be a way to solve this problem using views. Say you have queries of the form:

    select . . .
    from table1 t1 . . .
    

    And you now want:

    select . . .
    from table1 t1 . . .
    where t1.field = 'x'
    

    You can solve this by doing the following steps:

    1. Rename table1 to something (say _table1):

      rename table table1 to _table1;
      
    2. Create a view with the name table1:

      create view table1 as
      select *
      from _table1
      where field = 'x';
      

    In general, I think it is a better idea to change existing queries (and views in MySQL can cause problems with optimization). However, there are some circumstances where this approach might be appropriate for quickly getting the changes you need.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c