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 '產品部','......'union2.刪delete
語法:
刪除:delete from 表名 [where 條件]
--從表中刪除id為2的 delete from product3 where pid=23.改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<100004.查select
語法:
1.查詢所有列:( * :代表所有列) select * from 表名
--emp是表名 select * from emp2.查詢部分列:select 列名1,列名2..from 表名
select empId,empName,empSex from emp3.條件查詢(where子語句) select 列名1,列名2.... from 表名 where 條件
--查詢性別為"男"的員工信息 select * from emp where empSex='男'--地址為"鄭州"或"北京"的員工信息 select * from emp where empAddress='鄭州' or empAddress='北京'4.查詢出員工所在城市(不需要重復數據顯示)
distinct 用來去除重復字段
select distinct(PeopleAddress) from People5.多條件查詢:查詢月薪大于等于10000的員工,或者月薪大于等于8000的女員工
and是兩個條件都必須成立,or是兩個條件成立一個就可以了
select * from People where PeopleSalary>=10000 or (PeopleSalary>=8000 and PeopleSex='女')總結
以上是生活随笔為你收集整理的Sql Server 的基本增删改查语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网易云音乐java爬虫_用Java实现网
- 下一篇: uefi模式下win10安装双系统ubu