增加数据:insert
inset into 表名 (插入到哪些列) values (插入的值);
例如:inset into msg (id,title,content) values (6,'nihao','zhongguo');
插入部分列:
如果只想插入部分列就在msg后面那个小括号里写入你想插入哪些列:然后插入值;
例如:insert into msg (id,title) values (7,'woshi');
主键自增插入
desc msg
:查看表的结构
以后我们看到某一个列,它的key 这里写的PRI就是代表Primary key(主键的意思),并且Extra(额外增加)有一个auto_increment(自增长功能),我们可以不用写id(uid)列;
插入所有列的简写
insert into msg values(9,'ni','aiwoma');
简写必须写全;简写不能插入部分数据;只能插入全部;列名可以不写但是后面的值,每一列的每一个都要写全;
一次插入多行数据:
insert into msg values(10,'suan','le'),(11,'ni','ai'),(12,'de','shita');
注意
字符串必须加引号,不加引号会被当成列名;列名、数字什么的可以不加引号;
id(uid)不能重复;
修改数据:update
update 表名 set 要修改的数据 where 修改哪一行
update msg set content='xi' where id = 3;
不加where的话会把所有你要修改的数据类型改为一个
修改一行中的多个数据
update msg set title='niai',content='woma' where id=4;
注意逗号分隔数据;
update所有行:
不加where限制条件,所有数据都变成一样;
数据都是不可逆的除非有备份否则丢失了就找不回了;
删除数据:delete
delete from 表名 where 哪一行
delete from msg where id=12;
如果不加限制条件where就会把所有数据删掉;
删除时以行为单位;
查数据:select(只按主键查询)
查询某一个表所有列
select from 表名;(代表所有列)
select *from msg;
查询一行:
select *from 表名 where 第几行;
select *from msg where id=1;
查询多行:
select *from 表名 where 哪几行;
select *from 表名 where id>=3;
查询某几行的某几列:
select 列名 from 表名;
select id from msg;
(因为*代表的是所有列所以,我们单独写列名就会显示相应的)
select 列名,列名 from 表名 where 哪一行;
select title,content from msg where id=9;
select title,content from msg where id<=9;
版权声明:版权归 怪友 所有,转载请注明出处!
本文链接:http://www.geeh.cn/archives/66/
如果博客出现404或链接失效,请留言或者联系博主修复!