1、mysql数据类型
可参考菜鸟教程,链接如下:
https://www.runoob.com/mysql/mysql-data-types.html
对于数据类型要按需使用,日期时间按格式,字符串数字按大小和长度
2、向表中插入数据
方式一:insert into 表名 values(各字段的值);
方式二:insert into 表名(字段1,字段2,...字段n)values(选中字段的值,其它为默认值或NULL);
insert into pet values('狗','me','dog','1','2002-1-2');
或者
insert into pet('name','owner') values('猫','you');
3、查询插入的数据
select * from 表名;
select * from pet;
#返回结果
+------+-------+---------+------+------------+
| name | owner | species | sex | brith |
+------+-------+---------+------+------------+
| 狗 | me | dog | 1 | 2002-01-02 |
| you | 猫 | NULL | NULL | NULL |
+------+-------+---------+------+------------+
2 rows in set (0.00 sec)
4、从表中删除数据
delete from 表名 where 条件;
delete from pet where name='狗';
#返回结果
Query OK, 1 row affected (0.03 sec)
mysql> select * from pet;
+------+-------+---------+------+-------+
| name | owner | species | sex | brith |
+------+-------+---------+------+-------+
| you | 猫 | NULL | NULL | NULL |
+------+-------+---------+------+-------+
1 row in set (0.01 sec)
5、修改表中数据
update 表名 set 字段1=值1,字段2=值2.... where 条件;
#原表
select *from pet;
+------+-------+---------+------+-------+
| name | owner | species | sex | brith |
+------+-------+---------+------+-------+
| 猫 | 猫 | NULL | NULL | NULL |
+------+-------+---------+------+-------+
1 row in set (0.00 sec)
修改操作
update pet set owner='you' where specise is NULL;
#返回结果
mysql> select *from pet;
+------+-------+---------+------+-------+
| name | owner | species | sex | brith |
+------+-------+---------+------+-------+
| 猫 | you | NULL | NULL | NULL |
+------+-------+---------+------+-------+
1 row in set (0.01 sec)
网友评论