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='女')

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐