Java教程

SQL再学习plus

本文主要是介绍SQL再学习plus,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

DML

添加数据

代码实现

mysql>  select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 1    |
| he   | 2    | 2    |
+------+------+------+
2 rows in set (0.01 sec)

mysql> insert into stu(name,id,sex) values("小爽",1,"女");
Query OK, 1 row affected (0.01 sec)

mysql> select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 1    |
| he   | 2    | 2    |
| 小爽 | 1    | 女   |
+------+------+------+
3 rows in set (0.01 sec)

修改数据

代码实现

mysql> select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 男   |
| he   | 2    | 2    |
| 小爽 | 1    | 女   |
| 小程 | 2    | 男   |
+------+------+------+
4 rows in set (0.02 sec)

mysql> update stu set sex = "男" where name = "he";
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 男   |
| he   | 2    | 男   |
| 小爽 | 1    | 女   |
| 小程 | 2    | 男   |
+------+------+------+
4 rows in set (0.00 sec)

删除数据

代码实现

mysql> select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 男   |
| he   | 2    | 男   |
| 小爽 | 1    | 女   |
| 小程 | 2    | 男   |
+------+------+------+
4 rows in set (0.00 sec)

mysql> delete from stu where name = "he";
Query OK, 1 row affected (0.01 sec)

mysql>  select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 男   |
| 小爽 | 1    | 女   |
| 小程 | 2    | 男   |
+------+------+------+
3 rows in set (0.00 sec)

DQL

代码实现

mysql> select name , sex from stu;
+------+------+
| name | sex  |
+------+------+
| xue  | 男   |
| 小爽 | 女   |
| 小程 | 男   |
+------+------+
3 rows in set (0.00 sec)

代码实现

mysql> select distinct sex from stu;
+------+
| sex  |
+------+
| 男   |
| 女   |
+------+
2 rows in set (0.03 sec)

起别名
代码实现

mysql> select name as "姓名",sex "性别" from stu;
+------+------+
| 姓名 | 性别 |
+------+------+
| xue  | 男   |
| 小爽 | 女   |
| 小程 | 男   |
+------+------+
3 rows in set (0.00 sec)
这篇关于SQL再学习plus的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!