mysql基础语法 字段

#插入字段

mysql> desc student;

+-------+----------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+----------+------+-----+---------+-------+

| uid | int(10) | YES | | NULL | |

| names | char(20) | YES | | NULL | |

| age | int(11) | YES | | NULL | |

+-------+----------+------+-----+---------+-------+

mysql> insert into student values(1,'xiao',20);

Query OK, 1 row affected (0.04 sec)

mysql> select * from student;

+------+-------+------+

| uid | names | age |

+------+-------+------+

| 1 | xiao | 20 |

+------+-------+------+

1 row in set (0.00 sec)

插入指定字段

mysql> insert into student (uid,name) values (2,'hong');

Query OK, 1 row affected (0.00 sec)

mysql> select name,uid from student;

+------+------+

| name | uid |

+------+------+

| xiao | 1 |

| hong | 2 |

+------+------+

2 rows in set (0.00 sec)

#查看指定的数据库的表

mysql> select database();

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id: 10

Current database: book

+------------+

| database() |

+------------+

| book |

+------------+

1 row in set (0.01 sec)

mysql> select * from book.student;

+------+------+------+

| uid | name | age |

+------+------+------+

| 1 | xiao | 20 |

| 2 | hong | NULL |

+------+------+------+

2 rows in set (0.00 sec)

#删除指定表

mysql> select * from student where uid=1;

+------+------+------+

| uid | name | age |

+------+------+------+

| 1 | xiao | 20 |

+------+------+------+

1 row in set (0.00 sec)

mysql> delete from student where uid=1;

Query OK, 1 row affected (0.00 sec)

#删除为空的行

mysql> delete from student where age is null;

Query OK, 1 row affected (0.00 sec)

#更新字段

mysql> select * from student;

+------+------+------+

| uid | name | age |

+------+------+------+

| 3 | hong | 30 |

| 2 | aaa | 20 |

| 1 | bbb | 30 |

+------+------+------+

3 rows in set (0.00 sec)

mysql> update student set age=26 where uid=1;

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from student;

+------+------+------+

| uid | name | age |

+------+------+------+

| 3 | hong | 30 |

| 2 | aaa | 20 |

| 1 | bbb | 26 |

+------+------+------+

3 rows in set (0.00 sec)

#更新表指定两个字段

mysql> update student set uid=3 where age=30 and name="ccc";

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select distinct * from student;

+------+------+------+

| uid | name | age |

+------+------+------+

| 5 | hong | 30 |

| 2 | aaa | 20 |

| 1 | bbb | 26 |

| 4 | ccc | 20 |

| 3 | ccc | 30 |

+------+------+------+

5 rows in set (0.00 sec)

原文发布于微信公众号 - 从零开始的linux(gh_4a9d788f5f27)

原文发表时间:2017-06-28

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏性能与架构

Mysql 查看表及索引空间大小

查看数据库占用空间 SELECT CONCAT(ROUND((sum(DATA_LENGTH)+sum(INDEX_LENGTH))/(1024*1024),2...

34850
来自专栏Netkiller

数据库安全·时间一致性

以下节选择《Netkiller Architect 手札》地址 http://www.netkiller.cn/architect/ 接下来几周的话题是数据库安...

37170
来自专栏别先生

MYSQL中约束及修改数据表

MYSQL中约束及修改数据表 28:约束 约束保证数据的完整性和一致性 约束分为表级约束和列级约束 约束类型包括:     NOT NULL(非空约束)   ...

23580
来自专栏杨建荣的学习笔记

相同update语句在MySQL,Oracle的不同表现(r12笔记第30天)

今天有个朋友问我一个SQL问题,大体是一个update语句,看起来逻辑没有问题,但是执行的时候却总是报错。 语句和报错信息为: UPDATE paymen...

37870
来自专栏用户2442861的专栏

mysql索引index相关命令

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/haluoluo211/article/d...

20920
来自专栏我的博客

MYSQL死锁问题

如果insert或update用到了同样的索引也会造成死锁。 比如 update table_a set name = ‘test1’ where id =...

37560
来自专栏Python、Flask、Django

mysql视图,ThinkPHP视图

17840
来自专栏nnngu

019 单例模式的5种写法

单例模式的定义:保证一个类仅有一个实例,并提供一个访问它的全局访问点! 1、懒汉 public class Singleton { private st...

29940
来自专栏Clive的技术分享

MySQL ORDER BY主键id加LIMIT限制走错索引

67030
来自专栏跟着阿笨一起玩NET

sql server根据表中数据生成insert语句

修正了表中的字段如果是SQL中的关键字(如Order)时,生成的脚本执行会出错的bug

14910

扫码关注云+社区

领取腾讯云代金券