简体   繁体   English

通过 phpMyAdmin 将相同的数据添加到所有行的一列 (mySQL)

[英]add identical data to one column for ALL rows (mySQL) via phpMyAdmin

I am creating my first (,) database.我正在创建我的第一个 (,) 数据库。 and I have run into an issue that I cannot seem to locate the answer for.我遇到了一个我似乎无法找到答案的问题。

I have put an "added on" field in a table (among other things ofc), and since I'm the one adding it, I want to put the same date in the entire column.我在表中放置了一个“添加”字段(除其他外),并且由于我是添加它的人,所以我想在整个列中放置相同的日期。 The idea is that if there is a new item added at a later date, it will have that date, but the data initially populated should all have the same date.这个想法是,如果以后添加了一个新项目,它将有那个日期,但最初填充的数据应该都有相同的日期。

How?如何? Please don't tell me one row at a time....请不要一次告诉我一行......

Just add the column to the table and then run an update query只需将列添加到表中,然后运行更新查询

update yourtable set nameofyournewfield = 'yourdate' 

This will update all rows currently in the db, while the new rows will gettheir value (or have the default value you provided)这将更新数据库中当前的所有行,而新行将获得它们的值(或具有您提供的默认值)

Another possibility in addition to @Nicola's answer is to use the DEFAULT argument in add column.除了@Nicola 的回答之外,另一种可能性是在添加列中使用 DEFAULT 参数。

You can set default property of that column to any date and it will replicate that for all rows as long as you don't specify any value for that column while inserting and when you want to insert a different value just specify it in the insert statement.您可以将该列的默认属性设置为任何日期,只要您在插入时没有为该列指定任何值,它就会为所有行复制该属性,并且当您想要插入不同的值时,只需在插入语句中指定它.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM