zoukankan      html  css  js  c++  java
  • mysql

    C/S:Client Server
    B/S:Brower Server

    php主要实现B/S

    .net IIS java TomCat

    LAMP: Linux系统 A阿帕奇服务器 Mysql数据库 Php语言

    mysql:常用代码

    create table CeShi1
    (
    Uid varchar(50) primary key,
    Pwd varchar(50),
    Name varchar(50),
    Nation varchar(50),
    foreign key(Nation) references Nation(Code)
    )

    写查询语句需要注意:
    1.创建表的时候,最后一列后面不要写逗号
    2.如果有多条语句一起执行,注意在语句之间加分号分隔
    3.写代码所有符号都是半角的

    关系型数据库:表和表之间是有关系存在的


    创建表的几个关键字:
    1.主键:primary key
    2.非空:not null
    3.自增长列:auto_increment
    4.外键关系:foreign key(列名) references 表名(列名)


    CRUD操作:

    1.添加数据:
    insert into Info values('','','','','') 要求values括号里面的值的个数要和表里面列数相同
    insert into Info (Code,Name) values('','') 添加指定列的值

    2.修改数据
    update Info set Name = '张三' where Code = 'p001'

    3.删除数据
    delete from Info where Code = 'p001'


    查询数据:

    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 '_迪%' %代表任意多个字符 _代表一个字符

    10.离散查询
    select * from Car where Code in ('c001','c002','c003','c004')
    select * from Car where Code not in ('c001','c002','c003','c004')

  • 相关阅读:
    java基础问题1
    基本数据类型,string类型的瞎扯,final喜欢干的事儿。final string
    关于区块链不懂的东西
    需求更新表属性
    用户体验——响应时间
    后台运行任务nohup xxxxxx &
    jenkins打包maven工程发现有些包下载不下来
    jenkins复选框插件Extended Choice Parameter plugin
    jmeter上传文件tips
    airflow 简介
  • 原文地址:https://www.cnblogs.com/xingfudehuanyan/p/5421544.html
Copyright © 2011-2022 走看看