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 '张_' 

  • 相关阅读:
    python字符串操作
    python学习【一】基础入门
    markdown 编辑器
    jenkins学习笔记-安装
    算法
    python 修改文件内容
    python基础,python第四课
    python基础,python第三课
    python基础,python第二课
    python基础,python第一课
  • 原文地址:https://www.cnblogs.com/god3064371/p/11439536.html
Copyright © 2011-2022 走看看