美文网首页
数据库基础命令

数据库基础命令

作者: 我要改名 | 来源:发表于2019-11-28 23:21 被阅读0次

    mysql:   -u root -p密码 :进入mysql   name:表/库/名  desc name:查看表详情

    增:insert into name value(对应字段,对应字段....)插入单/多条属性

    create database name: 创建库   show databases:查看所有库

    create table name(字段 类型,字段 类型....):创建表 show tables:查看所有库

    alter table name add 字段 字段类型 :给name表创建新字段

    删:

    alter table name drop 字段; 删除字段

    改:

    alter table name rename to newname:更改表名

    alter table name change 旧字段 新字段 新类型;更改字段以及其类型,类型不符会报错

    查:

    select * from name:查看表内属性  select * from name where is null\not null:空\非空筛选

    select * from name where 字段 like " x%": 模糊查询

    select * from name where 字段 between x and/or/等 y;范围查询

    排、整理:

    select * from name order by 字段:根据单条字段排序

    select distinct 字段 from name:去重指定字段

    select count(字段) from name;单字段数据计数 count替换avg sum等亦可

    select 字段1,group_concat(字段2) from name group by 字段1:根据字段一分组 列出字段二

    select 字段1 from name group by 字段1,字段2having 字段2 :条件判断 聚合筛选字

    select 分组字段1,count(分组字段2)as 别名 from name group by :字段一分组计数

    select 字段1,字段二 from name 字段1=x and 1=1:根据字段一自动匹配字段二

    select 字段1,字段二 from name 字段1=x and 1=1:根据字段一自动匹配字段二

    约束类型(对应关键字): 默认 非空 唯一 自增 主键 外键

    关键字(对应约束类型):default  not    unique auto_increment  primary  foreign

                                                          null      key                                    key        key

                                                                                (与主键绑定必须)(非空和唯一)

    表与表的链接:

    相关文章

      网友评论

          本文标题:数据库基础命令

          本文链接:https://www.haomeiwen.com/subject/zjmiwctx.html