zoukankan      html  css  js  c++  java
  • 了解数据库语句

    创建表:

    create table Ceshi

    (

             Uid varchar(50) primary key,

             Pwd varchar(50),

             Name varchar(50),

             Nation varchar(50),

             foreign key(Nation) reference Nation(Code)

    )

    写查询语句需要注意:

    1.创建表的时候,最后一列后面不要写逗号

    2.如果有多余语句一起执行,注意在语句之间加分号分隔

    3.写代码所有符号都是半角的

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

    创建表的几个关键字:

    1.主键:primary key

    2.非空:not null

    3.自增长列:auto_increment

    4.外键关系:foreign key(列名) reference 表名(列名)

    CRUD操作:

    1.添加数据:

    insert into 表名 values('','','','')  要求values括号里面的值的个数要和表里面列数相同

    insert into 表名(列名,列名)   添加指定列的值

    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=' '   一个条件

    select*from info where name=' ' and nation=' '   两个条件并的关系

    select*from info where name=' ' or nation=' '      两个条件或的关系

    3.排序查询

    select*from info order by birthday    默认升序排列asc  如果要降序排列 desc

    select*from info order by brand,oil desc    多列排序

    4.聚合函数

    select count(*) from info    取个数

    select sum(price) from car 查询price列的和

    select avg(price) from car 查询price列的平均值

    select min(price)/max(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 (' ',' ',' ',' ')

    select*from car where code not in (' ',' ',' ',' ')

  • 相关阅读:
    Python 字符串格式化
    centos 7 & 6 优化脚本
    centos7.X 系统初始化>>优化
    重新嫁接rm命令
    ArcGIS Engine 10 开发常见问题的解决方法
    数据提交成功后如何避免alert被window.location.reload()影响
    服务器端IIS中部署带Office组件程序
    常用正则表达式
    C#解析XML
    使用Spire.Doc组件利用模板导出Word文档
  • 原文地址:https://www.cnblogs.com/yongjiapei/p/5514384.html
Copyright © 2011-2022 走看看