5月28日晚,MySQL的学习

2013年5月28日晚
PHP学习(PHP about MySQL)
    数据库的构成:
        MySQL数据库 -> Databases -> tables -> 字段(字段类型,内容)

    数据类型:
        int,smallint
            常用点击量,编号,真假
        char,varchar
            char最大255字节,varchar更长并伸缩,常用标题,姓名,关键字
        Date,datetime
            日期,固定格式:xxxx-xx-xx(Date) xx:xx:xx(Datetime具体到分秒)
        float,double
            小数
        Text,longtext
            没长度限制,用于新闻内容,长内容
    
    SQL语句:
        插入:
            Insert into  表(字段1,字段2) values(值1,值2)
            Insert into 表 values(值1,值2) ,按照数据库一条数据顺序插入
            Insert into 表 set 字段1=值1,字段2=值2...
        查询:
            Select 字段1,字段2,.. from 表
            Select * 或 函数(字段) from 表
                函数: count(*)  统计条数
                      sum(字段),avg(),max(),min()
                ex: Select sum(price) from table
            Select 字段1,字段2 .. from 表 where 条件
            Select 字段1,字段2 .. from 表 where 字段 (not) like '%值%'
                %:匹配任意字符和次数
            Select 字段1,字段2 .. from 表 where 字段 (not) in (值1,值2,值3..)
                效率比较低
            Select 字段1,字段2 .. from 表 group by 字段
                去除重复项
            Select 字段1,字段2 .. from 表 order by 字段 [desc/asc]
                默认正序排序,组合:order by id asc,name desc
            Select 字段1,字段2 .. from 表 limit 起始位(from 0),条数
                limit 0,5  //从第1位开始取5条
                limit 5    //从第1位开始取5条,简化
            查询语句遵循顺序规则:WGOL --> where,group by,order by,limit

        修改:
            Update 表 set 字段=值,字段=值,[where][group][order][limit]

        删除(一行):
            delete from 表 WGOL


        


posted @ 2013-06-04 20:52  长溪  阅读(152)  评论(0编辑  收藏  举报