php 如何在单列 MySQL Query 中设置所有值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13612104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:46:36  来源:igfitidea点击:

How to set all values in a single column MySQL Query

phpmysqlsqlsql-update

提问by cwiggo

I've made a new tuple called 'description' in a table.

我在表格中创建了一个名为“描述”的新元组。

Just want a query to set all the 'description' tuples for my already created data to a certain piece of text.

只是想要一个查询将我已经创建的数据的所有“描述”元组设置为某段文本。

E.g. of fundamental 'update' query, but not sure if it is not the right method to use:

例如基本的“更新”查询,但不确定它是否不是正确的使用方法:

UPDATE suppliers SET name = 'HP'WHERE name = 'IBM'; 

Any suggestions?

有什么建议?

回答by cwiggo

Sorted

已排序

I Just used:

我刚用过:

UPDATE suppliers SET description = 'business'

This setS all the description FIELDS in my table to the string "business".

这将我表中的所有描述字段设置为字符串“business”。

Thanks for the suggestions.

感谢您的建议。

回答by Kermit

The formatting of the query you've provided is correct. Before running an UPDATEor DELETEit's always wise to run a SELECTof that query to make sure that is the change you want to make.

您提供的查询格式正确。在运行UPDATEor之前运行该查询的 a 以确保这是您想要进行的更改DELETE总是明智的SELECT

Your test query would be:

您的测试查询将是:

SELECT name FROM suppliers WHERE name = 'IBM';

However, the query you've provided will not update the descriptioncolumn. To do this, you would need something like:

但是,您提供的查询不会更新该description列。为此,您需要以下内容:

UPDATE suppliers SET description = 'HP' WHERE name = 'IBM';

After executing this UPDATE, you can run this query to validate your result:

执行此操作后UPDATE,您可以运行此查询来验证您的结果:

SELECT name, description FROM suppliers WHERE name = 'IBM';

回答by Mitul Maheshwari

This will change the filed status = "deactivate" where table name is :- user

这将更改归档状态=“停用”,其中表名是:-用户

 Session session=null;
    int rows=0;
     try {
           session =HibernateUtil.getSessionFactory().openSession();
           Query query = session.createQuery("UPDATE user  SET status = 'deactivate'");
           rows = query.executeUpdate();
         //  result = query.list();
        } catch (HibernateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }finally
    {
        session.close();
    }