mysql> insert into student (sno,sname,sex,birth) values(1,'张三','男','1995-10-23');
Query OK, 1 row affected (0.00 sec)
mysql> select * from student;
+------+-------+------+------------+
| sno | sname | sex | birth |
+------+-------+------+------------+
| 1 | 张三 | 男 | 1995-10-23 |
+------+-------+------+------------+
1 row in set (0.00 sec)
mysql> insert into student (sno,sname,sex,birth) values(2,'李四','女','1995-10-23');
Query OK, 1 row affected (0.01 sec)
mysql> select * from student;
+------+-------+------+------------+
| sno | sname | sex | birth |
+------+-------+------+------------+
| 1 | 张三 | 男 | 1995-10-23 |
| 2 | 李四 | 女 | 1995-10-23 |
+------+-------+------+------------+
2 rows in set (0.00 sec)
mysql> insert into student values(3,'王五','男','1996-05-12'),(4,'赵六',null,'1996-3-15');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from student;
+------+-------+------+------------+
| sno | sname | sex | birth |
+------+-------+------+------------+
| 1 | 张三 | 男 | 1995-10-23 |
| 2 | 李四 | 女 | 1995-10-23 |
| 3 | 王五 | 男 | 1996-05-12 |
| 4 | 赵六 | NULL | 1996-03-15 |
+------+-------+------+------------+
4 rows in set (0.00 sec)
把sno等于0的性别修改为‘女’
mysql> update student set sex='女' where sno=0;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
update 表名 set 列1=列1值, 列2=列2值 where 列N=列N值;
一般更新语句需要加上where子句已定位要修改的行,如果不加将会修改所有行相应的列;如果修改多个列对应的值,用“逗号”隔开各个列 。
删除sno=0的行
mysql> delete from student where sno=2;
delete from 表名 where 列N=列N值;
有些数据库如oracle可以省略delete后面的from,mysql不可以;一般删除语句需要加上where子句已定位要删除的行,如果不加会删除整个表的所有行。
weibo@:白菜先森