問題:有兩個不同的表,其中都有乙個編號的字段,而且儲存的內容是相同的,需要將一張表中的另外一些字段依據編號去與另乙個表中編號對應來更新到另乙個表中。
方法:由於在sql中是不支援同時更新多條包含編號的資料的,所以當我們要更新多條資料的時候我們需要進行逐條的更新操作,這個時候我們需要用到游標。游標是只能在儲存過程中執行的,所以我們需要建立乙個儲存過程
create
procedure
[dbo]
.[pp5_in_money]
asdeclare
@tvarchar
(50),
@in_money
decimal
(18,2)
begin
declare
ttt_cusor
cursor
for
select
pur_payment_req
.proposer_no
,pur_payment_req
.in_money
from
pur_payment_req
,pur_payment
where
pur_payment_req
.proposer_no
=pur_payment
.req_no
--將搜到的資料放入到游標
ttt_cusor中
open
ttt_cusor
fetch
next
from
ttt_cusor
into@t,
@in_money
--讀取ttt_cusor
游標中的第一條資料
while
@@fetch_status
=0begin
update
pur_payment
setpur_payment
.in_money
=@in_money
where
pur_payment
.req_no=@t
fetch
next
from
ttt_cusor
into@t,
@in_money
--讀取ttt_cusor
游標中的下一條資料
endclose
ttt_cusor
deallocate
ttt_cusor
EntityFramework更新多條資料 8萬
此文主要用做記錄用 原因 資料庫遷移,需要轉換大量使用者資料,兩資料某欄位加密方式不一致需要批量轉換 注 轉換程式用了entityframework 過程 1.讀取所有需要轉換資料至list 2.採用parallel.foreach對list進行批次資料轉換 3.將轉換後的list資料按一定數量進行...
SQL表單條資料插入與多條資料插入
建立使用者表 create table users uid int identity 1,1 not null,uname varchar 20 not null,upassword varchar 20 not null,uage int,u bit default 0 not null,sele...
mysql 中實現多條資料同時更新
有時間我們需要對一張表進行批量資料的更新。首先我們想的是update 語句。比如對一張訂單表order info 多條資料更新,update order inifo set order code case order id when 1 then abc when 2 then bcd when 3...