MySQL, add column 'FullNameReverseOrder' with data from fullname column and change (FName, LName) to (LName, FName)
P粉948258958
2023-08-17 17:32:04
<p>I want to add a new column named FullNameReverseOrder to a table named NameTable, where the information of FullName is arranged in the order of FirstName LastName, and the FullNameReverseOrder will be saved in the order of LastName FirstName. </p>
<p>Here is a table you can use: </p>
<pre class="brush:php;toolbar:false;">create table NameTable (ID int, FullName varchar(100), age int, primary key(ID));
insert into NameTable (ID, FullName, age) values(1, 'ben thompson', 23);
Add a new column named FullNameReverseOrder:
alter table NameTable add column FullNameReverseOrder varchar(100) ...don't know what to do here... after FullName;</pre>
<p><br /></p>
Some points to consider.
Based on the question
Consider the following data example where the
FullName
column consists of up to three words separated by spacesInquire,
result,
First make changes by modifying the table structure. If there are a large number of transactions, I recommend locking the table appropriately
To update the newly added columns LastName, MiddleName and FirstName, use the following command:
choose,
result
Now, if you want this process to happen automatically, consider creating a trigger.
Insert test value
result
View example