日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Sql Server 的基本增删改查语句

發布時間:2023/12/9 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Sql Server 的基本增删改查语句 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.增insert

語法:

方式一:普通寫法:insert into 表名(列名1,列名2...) values(值1,值2...)

方式二:簡寫: insert into 表名 values(值1,值2....) 要求必須值要與列對應

insert into board(boardName) values('C語言')insert into student(stuId,stuName,stuAge,birthDay,stuAddress) values(1,'張三',30,'1985-01-01','河南')insert into student values(2,'李四',20,'1995-01-01','河南')insert into student(stuName,stuAge,birthDay,stuAddress,stuId) values('張三2',30,'1985-01-01',河南',3)

一次性插入多行數據:

insert into Department(DepartmentName,DepartmentRemark) --union代表連接 select '測試部','......'union select '實施部','......'union select '產品部','......'union

2.刪delete

語法:

刪除:delete from 表名 [where 條件]

--從表中刪除id為2的 delete from product3 where pid=2

3.改update

語法:

修改: update 表名 set 列名1=值1, 列名2=值2... [where 條件]

--根據id去更新狀態 (需要寫sql語句去進行操作數據) --update PLAN_ORDER set MO_SIGN='CLOSED' where MO_ID=" + MO_ID --更新PLAN_ORDER這個表 --where是判斷條件通過這個id(MO_ID=" + MO_ID )去更新 --要更新成什么狀態 MO_SIGN='CLOSED' update PLAN_ORDER set MO_SIGN='CLOSED' where MO_ID= MO_ID

例1:工資調整,給每個人加薪1000元

給people表中的 peopleSalary加薪

update People set PeopleSalary=PeopleSalary+1000

例2:工資調整,給員工編號為7的人加薪1000元

給people表中的 peopleSalary加薪,但此處有條件就是員工編號為7的人

update People set PeopleSalary=PeopleSalary+1000 where PeopleId=7

例3:工資調整,將軟件部(部門編號1)人員工資低于10000的調整成10000

此處的條件需要進行判斷DepartmentId=1 and PeopleSalary<10000

update People set PeopleSalary=10000 where DepartmentId=1 and PeopleSalary<10000

4.查select

語法:

1.查詢所有列:( * :代表所有列) select * from 表名

--emp是表名 select * from emp

2.查詢部分列:select 列名1,列名2..from 表名

select empId,empName,empSex from emp

3.條件查詢(where子語句) select 列名1,列名2.... from 表名 where 條件

--查詢性別為"男"的員工信息 select * from emp where empSex='男'--地址為"鄭州"或"北京"的員工信息 select * from emp where empAddress='鄭州' or empAddress='北京'

4.查詢出員工所在城市(不需要重復數據顯示)

distinct 用來去除重復字段

select distinct(PeopleAddress) from People

5.多條件查詢:查詢月薪大于等于10000的員工,或者月薪大于等于8000的女員工

and是兩個條件都必須成立,or是兩個條件成立一個就可以了

select * from People where PeopleSalary>=10000 or (PeopleSalary>=8000 and PeopleSex='女')

總結

以上是生活随笔為你收集整理的Sql Server 的基本增删改查语句的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。