zoukankan      html  css  js  c++  java
  • 数据库增删改查部分操作

    对库和表的增删改查

    创建:

    create database xxx default character set utf8

    create table  yyy(

        aaa int,

        bbb varchar(10),

        ccc datetime

        ddd double

    )

    显示:

    show databases 

    show create database xxx

    show tables

    删除:

    drop database xxx

    drop table yyy

    修改:

    alter database xxx default character set gbk

    ---选中库  use xxx

    alter table yyy add column eee int    //添加字段

    alter table yyy drop column aaa  //删除

    alter table yyy modify column eee varchar(20)  //修改类型

    alter table  yyy change column eee fff varchar(20)   //改字段名

    alter table yyy rename to zzz  //改表明

    对数据的增删改查

    对表插入数据:

    insert into yyy values(1,'2','cc','数据数据')

    insert into yyy(aaa,ccc) values(1,'cc')

    修改数据

    update yyy set  ccc='数据',bbb='数' where id=2

    删数据跑路:

    delete from yyy where id=1

    delete from:可带条件,不可删约束,可回滚

    truncate table:不可带条件,可以删约束,不可回滚

    查询表中的数据

    select * from yyy

    select aaa,bbb from yyy

    select aaa as '编号',bbb as '成绩1' from yyy

    select aaa as '编号',(bbb+ccc) as '成绩2'  from yyy      //统计bbb和ccc的和,只能是数值类型。

    select distinct ddd from yyy    // dinstinct去除重复选项

    select * from yyy where aaa=1    //只统计满足where 后条件的数据

    select * from yyy where   ddd <> '数据'   // <>不等于

    select * from yyy where  eee is null    //   is null   。 is not null 。

    select * from yyy where  eee i=''     // 空字符串 ''

    模糊查询:  like       %随意字符, _一个字符

    select * from yyy where aaa like '%张%' 

    select * from yyy where aaa like '张_' 

  • 相关阅读:
    Ajax工作原理和原生JS的ajax封装
    HNU 13073 Ternarian Weights 解题报告
    如何在Eclipse中配置python开发环境
    C++中vector 容器的基本操作
    2014年百度实习生面试题及总结
    Python计算一个项目中含有的代码行数
    Linux环境下的GCC编译器与GDB调试工具介绍
    linux环境下Vim的配置
    计算机网络中好的期刊和会议
    hdu 1005解题报告
  • 原文地址:https://www.cnblogs.com/god3064371/p/11439536.html
Copyright © 2011-2022 走看看