页次: 1
数据表最重要的操作就增删改查。
增 -- 增加一条记录
删 -- 删除一条记录
改 -- 修改一条记录
查 -- 查找满足条件的记录
这里使用已经创建好的表tb001
表的创建 http://www.ipbbs.net/viewtopic.php?id=50
增加一条记录
mysql> insert into tb_001 (name, weight) values ('ipbbs', '1.1'); Query OK, 1 row affected (0.00 sec) mysql> insert into tb_001 (name, weight) values ('ipbbs2', '2.2') , ('www.ipbbs.net', '3.3'); Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 select * from tb_001; +----+---------------+--------+ | id | name | weight | +----+---------------+--------+ | 1 | ipbbs | 1.10 | | 2 | ipbbs2 | 2.20 | | 3 | www.ipbbs.net | 3.30 | +----+---------------+--------+ 3 rows in set (0.00 sec)
增加可以添加一条记录,也可以同时添加多条记录
删除操作
mysql> delete from tb_001 where id=1 Query OK, 1 row affected (0.03 sec) mysql> select * from tb_001; +----+---------------+--------+ | id | name | weight | +----+---------------+--------+ | 2 | ipbbs2 | 2.20 | | 3 | www.ipbbs.net | 3.30 | +----+---------------+--------+ 2 rows in set (0.00 sec)
where 后面的语句决定了删除什么,不删除什么。
where id > 10 ; 表示id小于10的都删除了。
修改
mysql> update tb_001 set name='www.ipbbs.net' where id=2; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from tb_001; +----+---------------+--------+ | id | name | weight | +----+---------------+--------+ | 2 | www.ipbbs.net | 2.20 | | 3 | www.ipbbs.net | 3.30 | +----+---------------+--------+ 2 rows in set (0.00 sec)
查找
select * from tb_001;
示例
mysql> select * from tb_001 where id = 2; +----+---------------+--------+ | id | name | weight | +----+---------------+--------+ | 2 | www.ipbbs.net | 2.20 | +----+---------------+--------+ 1 row in set (0.00 sec)
ipbbs.net
离线
页次: 1