简体   繁体   中英

How to copy over values from one column to another newly added column?

I am working on a web application that is up and running on a production server. I need to make some changes to the database but I am not sure what is the best way to go about this.

I have a table called Trips and it contains columns "maximum_guests", "minimum_guests", etc.

I need to add a column called "base_guests" and I want to give it a value of "maximum_guests" for existing entries in my table(production data). From this point forward Trips will only be created if both "base_guests" and "maximum_guests" are provided.

Is there a safe way to do this? I am using Php Symfony, mysql and doctrine if that helps.

You should first make an export of your database just in case. Then add the column to the table and run.

UPDATE Trips set base_guests = maximum_guests;

This will assign the value of maximum_guests to base_guests for each record in the Trips table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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