zoukankan      html  css  js  c++  java
  • mysql基础知识

    语句分类

    DDL 数据定义语句 create、drop、alter 定义不同的数据段、数据库、列、表、索引等数据库对象
    DML 数据操纵语句 insert、delete、update、select 添加删除更新和查询数据库记录,并检查数据完整性
    DCL 数据控制语句 grant、revoke 控制不同数据段直接的许可和访问级别的语句

    DDL的操作

    显示所有数据库

    show databases;
    

    进入一个数据库

    use database1;
    

    查看当前数据库中的所有表

    show tables;
    

    创建数据库

    create database test1;
    

    删除某数据库

    drop database test1;
    

    创建表

    create table table1(name1 type1,name2 type2,name3 type3,.....);
    

    table1是表名,name表示列名,type是列中数据的类型。

    查看某表

    desc table1;
    

    查看某表更全面的表定义信息

    show create table table1;
    

    删除某表

    drop table table1;
    

    修改表

    表类型

    alter table table1 modify name1 type*;
    

    type*是表中列name1的新类型

    增加表字段

    alter table table1 add column name_new type_new;
    

    删除表字段

    alter table table1 drop column name_drop;
    

    字段改名

    alter table table1 change name1 name_new type_new;
    

    修改字段排列顺序

    alter table table1 add name_new type_new after name_front;
    

    以上新创建一个字段name_new,类型type_new,放在原来的name_front字段下面(后面)

    alter table table1 modify name2 type2 first;
    

    以上将name2放在最前面。

    表改名

    alter table table1 name1 rename table_new;
    

    将表改名为table_new。

  • 相关阅读:
    Android Studio快捷键
    Eclipse常用快捷键
    沉浸式状态栏
    JAVA起名规范
    c语言求数组长度
    自定义checkbox风格
    退出所有应用,监控打开了什么活动
    android权限大全
    广播接收者Receiver
    ImageView的常用属性
  • 原文地址:https://www.cnblogs.com/rayshaw/p/9277549.html
Copyright © 2011-2022 走看看