zoukankan      html  css  js  c++  java
  • mysql

    Mtsql:常用代码
    Create table CeShi1
    (
         Uid varchar(50) primary key,
         Pwd varchar(50),
         Name varchar(50)
         Nation varchar(50),
         foreign key (Nation)  references Nation(Code)   //加外键关系    //references 引用    
    )
    写查询语句需要注意:
    1.创建表的时候,最后一列后面不要写逗号。
    2.如果有多条语句一起执行,注意在语句之间加分号分隔。
    3.写代码所有符号都是半角的。
    
    关系型数据库:表和表之间是有关系存在的
    
    创建表的几个关键字;
    1.主键:primary key
    2.非空: not null
    3.自增长列:auto_increment
    4.外键关系:foreign key (列名)  references 表名(列名)
    
    
    CRUD操作:  增删改查
    1.添加数据:
    Insert into 表名 values(‘’,‘’,‘’,‘’)要求values 括号里面的值的个数要求和表里面的列数相同
    Insert into Info (Code,Name) values(‘’,‘’)  添加指定列的值
    2.修改数据:
    Update info set Name=’张三’ where Code = ’p001’
    3.删除数据:
    Delete from info where Code = ‘p001’
    
    
    4.查询数据:
    
    1.普通查询:查所有的
    Select *from info    #查所有数据
    Select Code,Name from info  #查指定列
    
    2.条件查询
    Select *from info where Code =’p001’  #一个条件
    Select *from info where Name =’张三’ and Nation =’n001’  #两个条件并的关系
    Select *from info where Name =’张三’ or Nation =’n001’  #两个条件或的关系
    3.排序查询
    Select *from info order by Birthday  #默认升序排列asc  若果要降序排列  desc
    Select *from car order by Brand,Oil desc  #多列排序
    
    4.聚合函数
    Select count(*) from info  #取个数
    Select sum(price) from car   #查询price列的和
    Select avg(price) from car   #查询price列的平均值
    Select max(price) from car   #查询 price列的最大值
    Select min(price) from car   #查询 price列的最小值
    
    5.分页查询
    Select *from car limit n,m   #跳过n条数据取m条数据 
    
    6.分组查询
    Select brand from car group by brand    #简单分组查询
    Select brand from car group by brand having count(*)>2        #查询系列里面车的数量大于2的系列
    
    7.去重查询
    Select distinct brand from car
    
    8.修改列名
    Select brand as ‘系列’ from car
    
    9.模糊查询
    Select *from car where name like ‘奥迪%’    # %代表任意多个字符
    Select *from car where name like ‘_迪%’          # _代表一个字符 
    
    10.离散查询
    Select *from car where code in (‘c001’,’c002’,’c003’,’c004’)
    Select *from car where code not in (‘c001’,’c002’,’c003’,’c004’)
  • 相关阅读:
    Ajax XMLHttpRequest对象的三个属性以及open和send方法
    去空格
    绑定事件中 如可控制函数的执行次数
    我之理解---计时器setTimeout 和clearTimeout
    关于border边框重叠颜色设置问题
    YbtOj练习:二分5 飞离地球
    YbtOj练习:二分4 分割矩阵
    YbtOj练习:二分3 攻击法坛
    YbtOj练习:贪心3 最优密码
    YbtOj练习:二分2 最小时间
  • 原文地址:https://www.cnblogs.com/dianfu123/p/5463219.html
Copyright © 2011-2022 走看看