首先创建名为hxinfo的表
> create database hxinfo
;
SELECT -从数据库表中获取数据 UPDATE -更新数据库表中的数据 DELETE -从数据库表中删除 INSERT INTO -向数据库表中插入数据
增
新增一条
>insert into 表名 values
(全部列的值,用”
,“分割
);
>insert into 表名
(字段1
, 字段2
) values
(值1
, 值2
);
新增多行数据
>insert into 表名 values
(全部列的值
),
(全部列的值
)....;
>insert into 表名
(字段1
, 字段2
) values
(值1
, 值2
),(值1
, 值2
),(值1
, 值2
)....;
例如在hxtable表中插入一条员工信息:‘001’,‘wutong’,‘m’,‘20’.
> insert into hxtable values
('001','wutong','m','20')
删
> delete
from <表名>
[where <删除条件>
例:delete
from hxtable where name=
'wutong'
(删除表hxtable中列值为wutong的行)
删除整个表的数据
> truncate table <表名>
改
> update <表名>
set <列名=更新值>
[where <更新条件>]
例:update hxtable
set 年龄=18 where 姓名=
'wutong'
set后面可以紧随多个数据列的更新值(非数字要引号);where子句是可选的(非数字要引号),用来限制条件,如果不选则整个表的所有行都被更新。
查
查询所有数据行和列
>
select * from hxtable
查询表hxtable中性别为男的所有行,显示name列,并将name列改名为(姓名)显示
>
select name as 姓名
from hxtable where gender=
'男'