怎么用SQL語句修改指定字段的數(shù)值?
比如表里有一個字段,里面數(shù)據(jù)不相同,數(shù)據(jù)的共同特征是為3開頭,怎么把3開頭的數(shù)據(jù)改為5開頭。update table1 set aa= '5'+right(aa,len(aa)-1) where left(aa,1)='3'
搞定。
如何使用sql語句修改數(shù)據(jù)表中字段的值 要語句
語句為:update ,作用是修改表中的數(shù)據(jù)。
格式為:
Update 表名 set 列名=值
where 條件
update 表名 set 字段='要修改后的值' where 定位字段='值'
如:
update student set name='王剛' where id=1
---學(xué)號為1的同學(xué)名字改成王剛。
如何用sql語句修改表中字段值,值要取自另一張表
具體是這樣的:表1中有如下四個字段rn 編號,姓名,卡號,余額rn 1 張三 123 rn 2 李四 124 rn ....rn 100 若干 233rnrn 表2中有如下字段:rn 卡號,余額rn現(xiàn)在的問題我想把表1中的余額這個字段的內(nèi)容更新為表2中的余額,也就是說,表1中的卡號為123的余額更新為表2中卡號為123的余額。以卡號為索引。但表2中的記錄可能不只是表1一一對應(yīng)的,也就適說表2中有的記錄表1中時沒有的,而表1中有的記錄可能表2中也是沒有的,我表述的不太清楚,不知道各位能不能聽明白。rn 當(dāng)然我也知道兩個表有共同的索引字段,在編程的時候能夠根據(jù)這個字段到另外一個表里取值,這個先不考慮,我就是單純的想知道上面我描述的這個結(jié)果怎么用語句來實現(xiàn),是用update語句嗎?應(yīng)該加什么條件呢?謝謝各位,我的百度財富分不多,請諒解。那你就是要把凡是表1和表2相同的改了吧?
如果卡號無重復(fù)
這么寫
update 表1 t1 set t1.余額=(select t2.余額 from 表2 t2 where t2.卡號=t1.卡號)
財富是浮云,幫到你才是真的
--Sql By MySql 5.1
--update data in tab2
update tab2,tab1 set tab2.ye=tab1.ye where tab2.kh=tab1.kh
--insert data in tab2
insert into tab2 ( kh,ye) select kh,ye from tab1 where tab2.kh not in ( select kh from tab1)
用SQl語句更改表中一個字段的值
030030rn28005rn028010rn010002rn010003rn30004rn5002rn029009rn030040rn007003rn017002rn013007rn30034rn030033rn29007rn030031rn29008rn004002rn55001rn30009rn028002rn029005rn30014rn29011rn028001rn我有如上數(shù)據(jù)(這只是部分的),我想要的效果是如下rn030030rn028005rn028010rn010002rn010003rn030004rn005002rn029009rn030040rn007003rn017002rn013007rn030034rn030033rn029007rn030031rn029008rn004002rn055001rn030009rn028002rn029005rn030014rn029011rn028001rn030030rn028005rn028010rn010002rn010003rn030004rn005002rn029009rn030040rn007003rn017002rn013007rn030034rn030033rn029007rn030031rn029008rn004002rn055001rn030009rn028002rn029005rn030014rn029011rn028001rn主要想用SQl語句更新原有數(shù)據(jù)。本人菜鳥,希望大家指點。用update
set就可以了
update
表名
set
要修改的屬性和值
如果你要修改具體的某列的某個屬性可以在后面查出來用where
比如你說的a表中
id為1的數(shù)據(jù)中
b列下的值修改為2
update
a
set
b=2
where
id=1
sqlserver 寫法:
update tablea set a=case len(a) when 1 then '00000'+a when 2 then '0000'+a when 3 then '000'+a when 4 then '00'+a when 5 then '0'+a end
oracle寫法:
update talbea set a=case length(a) when 1 then '00000'||a when 2 then '0000'||a when 3 then '000'||a when 4 then '00'||a when 5 then '0'||a end
對菜鳥最好的辦法,導(dǎo)出這個表為excel格式,然后手動更改,然后導(dǎo)入回去
如何修改數(shù)據(jù)庫表中的某一個字段的值?
修改方法:
使用update語句。語法是:update table_name set column = value[, colunm = value...] [where condition];
[ ]中的部分表示可以有也可以沒有。
例如:update students set stu_name = "zhangsan", stu_gender = "m" where stu_id = 5;
相關(guān)推薦:
刑事涉外程序(涉外刑事案件審理流程)
委托公證錯誤賠償(房屋公證人需要承擔(dān)什么責(zé)任)
強(qiáng)制執(zhí)行賠償(民事賠償強(qiáng)制執(zhí)行期限)
拆遷賠償城市戶口(城市戶口可以享受農(nóng)村拆遷補(bǔ)償嗎)
刑事處罰算前科嗎(坐牢5年出來還算有前科嗎)