zoukankan      html  css  js  c++  java
  • day41


    1. 数据行

      #插入
      insert into 表名 (列1,列2) values (值1,值2);
      insert into student(id,name) values(2,'zs')
      insert into 表名 (列名1,列名2) select 列名1,列名2 from 表名;

      #查询
      select 列名 from 表名;
      select * from sutdnet;

      #删除
      delete fron 表名;(自增列会延续)
      truncate 表名;(自增列会重新开始)

      #修改
      update 表名 set 列名 = '值'[,列名 = '值'] where 条件

      #where ,and,or,not,<, >, != ,in, between
      delete from 表名 where id > 10
      delete from 表名 where id > 10 and name = 'xxx'
      select * from 表名 where id between 9 and 12
      select * from 表名 where id in (1,2,3,4)

      #通配符 % _
      select * from 表名 where name like 'ale%';
      select * from 表名 where name like 'ale_';

      #限制取几条 limit
      select * from 表名 limit 0,10 #(索引偏移量,取出多少条数据/offset2)

      #排序 order by
      select * from 表名 order by 列名 desc;
      select * from 表名 order by 列名 asc;
      select * from 表名 order by 列1 desc,列2 asc #如果前一列的值相等,会按照后一列的进一步的排序

      #分组 group by having
      select 列名,聚合函数(sum,count,max,min,avg) from 表名 group by 列名
      #ps:分组一般和聚合函数一起用,分组用来以某一个分组,聚合函数用来计算某一列,having用来对分组的结果进行筛选

      #连表操作
      select * from 表名,表名 where 表名.列名 = 表名.列名

      select * from 表名 left join 表名 on 表名.列名 = 表名.列名
      #左边的表全部显示,右边没有用到不显示
      select * from 表名 rigth join 表名 on 表名.列名 = 表名.列名
      #右边的表全部显示,左边没关联的用null显示
      1. 外键

        constraint fk_userinfo_depart('约束名称') foreign key('外键') references 表名('关联的键')


        #不能将创建外键的语句单独拿出来,如果在创建完表以后想要加外键关系,使用下例
        alter table 表名 add constraint fk_userinfo_depart('约束名称') foreign key('外键') references 表名('关联的键')
        #删除
        alter table 表名 drop foreign key 外键名称

        '''
        ps:外键关联的时候,必须关联的是表的主键ID
          主键的作用:加速查找,不能为空,不能重复
        '''

        #唯一索引(联合唯一索引)
        unique :该列的值不能重复
        create table t(
        id int,
           num int
           unique(num) #unique(id,num)
        )engine = Innodb charset = utf8    
  • 相关阅读:
    PHP无法使用file_get_contents或者curl_init()函数解决办法
    EXT 删除 监听
    PHP调试工具Xdebug安装配置教程
    Linux常用命令大全
    js中setInterval与setTimeout用法
    基于Web过程模拟的动态Web信息获取
    HNU2[J题]Modified LCS 扩展GCD
    SQL Server 2005定时备份维护操作步骤定时备份维护操作步骤定时备份维护操作步骤定时备份维护操作步骤
    object_id (N'...')是什么意思?
    使用TSQL来创建作业(这个比较好)
  • 原文地址:https://www.cnblogs.com/zhuqihui/p/11019877.html
Copyright © 2011-2022 走看看