将相同的固定值插入多行 [英] Insert the same fixed value into multiple rows

查看:78
本文介绍了将相同的固定值插入多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有列的表,我们称其为table_column,对于表的所有行,当前为null.我想将值"test"插入所有行的该列中.有人可以给我这个SQL吗?

I've got a table with a column, lets call it table_column that is currently null for all rows of the table. I'd like to insert the value "test" into that column for all rows. Can someone give me the SQL for this?

我尝试过 INSERT INTO table (table_column) VALUES ("test");,但这仅填充最后一行.如何一次完成所有行?

I've tried INSERT INTO table (table_column) VALUES ("test"); but that only populates that last row. How do I do all of the rows at once?

推荐答案

您正在寻找更新不插入.

UPDATE mytable
SET    table_column = 'test';

UPDATE将更改现有行的值(并且可以包含WHERE以使其仅影响特定行),而INSERT将添加新行(这使其看起来仅更改了最后一行,但实际上是添加具有该值的新行).

UPDATE will change the values of existing rows (and can include a WHERE to make it only affect specific rows), whereas INSERT is adding a new row (which makes it look like it changed only the last row, but in effect is adding a new row with that value).

这篇关于将相同的固定值插入多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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