如何在sql誾句select中根據某個字段值修改另外一

2021-04-26 06:22:25 字數 2719 閱讀 9899

1樓:語澍璐遠

update table set col2=case when col1 條件bai1 then 值

du1 when col1 條件2 then 值2;

或者分zhi為幾句修改dao

update table set col2=值1 where col1 條件1

update table set col2=值2 where col1 條件2

sql 語句中當乙個字段等於某值時怎樣讓另乙個字段等於另乙個值

2樓:

@aif(@a=x) 當乙個字段等於某值時

3樓:匿名使用者

sql="update 資料表 set 欄位名=字段值 where 條件表示式"

sql="select * from 資料表 where 欄位名=字段值 order by 欄位名 [desc]"

4樓:匿名使用者

update 表名 set 欄位2 = 值2 where 欄位1 = 值1

sql 語句 以某乙個欄位為條件 修改某乙個欄位的值

5樓:匿名使用者

示例:表名: poetry ;字段:p_type;  條件:p_type='1001';

sql 語句: 「update poetry set p_type ='aaa' where p_type ='1001'」

6樓:浪子_回頭

最簡單的方法就是使用資料庫視覺化工具,直接在表中修改,如果沒有資料庫視覺化工具,就使用cmd命令修改。

cmd命令修改字段例子:

**名稱class,表頭name、id。

修改語句:把  高一三班  改為 高一五班updata class set name = '高一五班'

where  name = '高一三班';

7樓:大野瘦子

update table set col2=case when col1 條件1 then 值1 when col1 條件2 then 值2;

或者分為幾句修改

update table set col2=值1 where col1 條件1

update table set col2=值2 where col1 條件2

sql修改字段屬性總結

1、修改表中字段型別 可以修改列的型別,是否為空)

alter table [表名] alter column [列名] 型別

2、向表中新增字段

alter table [表名] add [列名] 型別

3、刪除字段

alter table [表名] drop column [列名]

4、新增主鍵

alter table [表名] add constraint [ 約束名] primary key( [列名])

5、新增唯一約束

alter table [表名] add constraint [ 約束名] unique([列名])

6、新增表中某列的預設值

alter table [表名] add constraint [約束名] default(預設值) for [列名]

7、新增約束

alter table [表名] add constraint [約束名] check (內容)

8、新增外來鍵約束

alter table [表名] add constraint [約束名] foreign key(列名) referencese 另一表名(列名)

9、刪除約束

alter table [表名] add constraint [約束名]

10、重新命名表

exec sp_rename 『[原表名]』,』[新錶名]』

11、重新命名列名

exec sp_rename 『[表名].[列名]』,』[表名].[新列名]』

8樓:匿名使用者

update table_name set col_name1=***x where col_name2='***';

table_name表名,col_name1要修改的欄位名 col_name2做為條件的欄位名,***值。

9樓:

--並表更新

--表tableb,tablea; 欄位col01,col02,col03

update tableb

set colb = a.col01 + a.col02from tablea a

where tableb.col03 = 特定字串and tableb.col01 = a.col01 --並表的條件

10樓:匿名使用者

能把問題說明白些嗎?不知道你到底什麼意思,我的理解答案給你看看是不是你想要的:

1.修改表a中,***為女的salary(工資)增加500update a set salary=salary+500where ***='女'

11樓:匿名使用者

update table set 字段=要修改的值

where 字段=過濾條件

12樓:匿名使用者

update [表名] set [列1] = [值1],[列2] = [值2] where [列3] = [值3]

SQL如何在資料庫中查詢已知列名的所在表

select tab.name from syscolumns as colinner join sysobjects as tab on col.id tab.id where col.name item idx select table name from all tab columns whe...

php批量執行sql語句怎麼寫,如何在php中執行多條sql語句

php中利用陣列用mysql query批量執行sql語句。參考示例如下 思路 這裡採用乙個陣列.用explode 函式,將 query語句按照 炸開,然後迴圈執行即可 query delete from ecs goods attr where attr id 11 and goods id 22...

如何C 介面中為select動態新增資料

後台還是前台?後台的話用控制項是可以繫結資料來源的,datasource屬性繫結後再呼叫databind方法。如果 是前台就遍歷集合,dom操作建立option節點追加到select中。listhua shun list new list dataset ds getdataset datarow ...