mschocobo
mschocobo

Reputation: 62

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....

Upvotes: 1

Views: 3562

Answers (3)

RisingDragon
RisingDragon

Reputation: 11

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.

Upvotes: 0

Scott C Wilson
Scott C Wilson

Reputation: 20026

Another possibility in addition to @Nicola's answer is to use the DEFAULT argument in add column.

Upvotes: 0

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76880

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)

Upvotes: 6

Related Questions