SQLServer修改表數據


使用SSMS數據庫管理工具修改數據

修改任意一條或者多條都可以

1:打開數據庫,選擇數據表,右鍵點擊-》編輯所有行(如未配置,點擊編輯前200行)。

2、編輯需要修改的數據-》編輯完成后,右鍵點擊空白處-》選擇執行SQL即可編輯成功。

使用T-SQL腳本修改數據

修改單表中一行單列或者多列數據

語法:update 表名 set 列名1=值,列名2=值 where 條件;

示例一:update test1  set age='21' where id='1';

示例結果:

修改單表中多行一列或多列數據

語法:update top(數量) 表名 set 列名1=值,列名2=值2 where 條件;

示例:

update test1 set age='23' where id in ('1','2');

update test1 set age='22' where id between '3' and '4';

update test1 set age='23' where id>='5' and id <='6';

update top(2) test1 set age='23' where id>='5';

update test1 set age='23' where test1.id in (select top(2) id from test1 order by id desc);

示例結果:

多表關聯修改表中數據

語法:update 表1 set 表1.列1=值,表1.列2=值 from 表1 as a,表2 as b where a.列名=b.列名;

示例:update test1 set test1.name='李華',test1.sex='女' from test1 as a,test2 as b where a.classid=b.id;

示例結果:

 

總結:修改數據表數據,靈活組合修改數據列,數據源,查詢條件是關鍵。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM