2016/05/09(数据库)

DML:

向表中加SQL数据的语句是INSERT

insert into <表名>(列名) values(值列表) /增加相应列的属性

在数据库中mull和空数值不一样

insert into 表名(列名) select 到表的列 from 到表的名 /复制数据

update 表名 set 列A=新列A where 过滤条件 /更改已有数据

如果想将数据删除只需把值该为null

忽略where将会改变表中的列A 所有的值

delete from 表名 where 过滤条件  /删除一行数据或者多行

truncate table 表名 /直接删除所有的数据  而且不能恢复

 简单的数据查询(DQL)

在MYSQL 中所有的值和null相加都是null

投影操作:select 列A from 表名

表前缀名:select  p.name from 表名 as p

列别名:select 列A as A from 表名 as T

分页处理:

     select 列A from 表名 limit 开始序号,返回需要显示的多少行

     limit在mysql中代表从什么地方开始显示固定的行数

排出重复的数据:select distinct 列A from 表名

选择操作:

        select 列名 from 表名 where 条件 (单一条件)

        select 列A,列B from 表名 where 条件A and 条件B (多条件)

计算列:

        select 列A +列B  from 表名

选择操作:

       select * from 表名 where 列A=100 当列A=100为真的时候才执行

模糊查询(LIKE):

       select * from 表名 where 列A like '条件'

       %表示通配符(包含零个或多个字符)

       _ 表示只能通配单个字符

在数据库中查询值是否为null 不能=null 而是使用 is null 或者 is not null

排序操作(ORDER BY):

   select * from 表名 order by 列A  /以列A 升序排序

   select * from 表名 order by 列A desc /以列A 降序排序

 

posted @ 2016-05-09 20:56  丨她心如海般难测  阅读(102)  评论(0编辑  收藏  举报