Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the sql command used to update records in the basic table

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to update the records in the basic table using the sql command how to write, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

There is only one way to update the database, Update

Its standard format: Update table name set field = value where condition

However, there are differences depending on the source of the data:

1. Import from the outside

This is relatively simple.

Example:

Update tb set UserName= "XXXXX" where UserID= "aasdd"

2. Some internal variables, functions, such as time, etc.

Assign a function directly to a field

Update tb set LastDate=date () where UserID= "aasdd"

3. For some field variables + 1, common ones such as click-through rate, download times, etc.

This directly assigns the field + 1 to itself.

Update tb set clickcount=clickcount+1 where ID=xxx

4. Assign one field of the same record to another field

Update tb set Lastdate= regdate where XXX

5. Update a batch of records from one table to another

Table1

ID f1 f2

Table2

ID f1 f2

First update F1 f2 in table2 to table1 (same ID)

Update table1,table2 set table1.f1=table2.f1,table1.f2=table2.f2 where table1.ID=table2.ID

Update some records from the same table to other records

Table: a

IDmonthE_IDPrice1112212432154225

First, update the February product price in the table to mid-January.

Obviously, to find the same E_ID for ID in mid-February and mid-January and update price to mid-January

This can be handled with the above method, but because of the same table, in order to distinguish between two months, the table should be renamed.

Update a,an as b set a.price=b.price where a.E_ID=b.E_ID and a.month=1 and b.month=2

Of course, you can also query the February query first and update it with the method of 5.

Update a, (select * from a where month=2) as b set a.price=b.price where a.E_ID=b.E_ID and a.month=1 is all the contents of this article entitled "how to write sql commands to update records in the basic table". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report