浅谈 数据库的 增 删 查 改

1. 向数据库中添加一条数据:

alter table 表名 add 字段 类型 
//在 表中增加了 一个字段
insert into 表名 values('Bill','male')
//在表中增加的 dspcode,dspSex 字段上插入数据

2.数据库删除:

--删除数据库
drop database 数据库名

--删除表,先删除外键表,再删除主键表
drop table 表名

--无条件删除
delete from 表名

--有条件删除
--删除表中
delete
from 表名 where sName like '祥_' delete from 表名 where sName = '祥子' --删除Id为1的数据 delete from 表名 where sId = 1 --删除表 Drop table 表

3.数据库查找:

--直接查询表中的全部
select * from  表名
--使用like进行模糊查询
--查询所有带有王字的信息
select * from 表名 where stuName like '王%'
--查询第二字为 好字的信息
select * from 表名 where stuName like '_好%'
--根据Id查询
select * from 表名 where Id = 1
--嵌套子查询版
select * from 表名 where stuSpeciality in
(
 select stuSpeciality from 表名 where stuName = '李好'
)
and stuName <> '李好'

4.数据库修改:

--把表中id为5的name修改
update 表名 set tName = '李磊' where Id = 5

--把表中名name叫bill的所有名字修改
update 表名 set tName = '张强' where tName = 'Bill'
原文地址:https://www.cnblogs.com/szmh9192/p/8824669.html