• MySQL表的增删改查和列的修改(二)


    一、使用Like模糊查找搜索前缀为以“exam_”开头的表名
      show tables like 'exam_%' ;

      语句结束符号是;也是用G来表示

    二、MySQL表的CRUD

      2.1 创建表:
      Create table teacher(
      tea_no int,
      tea_name varchar(20)

      );

      2.2 查看表结构(描述表结构):
      Describe tbl_name;
      可以简写 desc tbl_name;

      数据库对应文件夹,表名对应文件夹中的内容,表名以.frm结尾

      2.3 修改表:
      修改表名 rename table old_tbl_name to new_tbl_name;可以同时修改多个表rename table
      old_tbl_name1 to new_tbl_name1,old_tbl_name2 to new_tbl_name2
      使用一个rename语句,交换两个表的名字
      支持跨数据库重命名
      rename table exam_user to `1234.user`
      可以利用跨数据库重命名表,可以为数据库重命名。
      创建一个新的数据库,旧数据库的表,都rename到新的数据库内。删除旧的数据库。

      2.4 删除表:
      drop table [if exists] db_name;

      三、列的CRUD
      3.1 增加一个新列
        Add :alter table exam_student add height int;
      3.2 修改一个列 字符串长度为:40;
        Modify: alter table exam_student modify stu_no varchar(40);
      3.3 删除一个列
        Drop:alter table exam_student drop height int;
      3.4 重命名一个列:把已有的列名score 改为 新的列定义fenshu
        Change:alter table exam_student change score fenshu int

       修改表中列格式:alter table tbl_name [add|modify|drop|change];

      四、修改表选项
      Alter [table|database] tbl_name 新的数据库或表选项
      alter table exam_student character set utf8;

  • 相关阅读:
    浅谈Linux的内存管理机制
    [SCM]源码管理 perforce状态的检测
    轻松构建Mysql高可用集群系统
    [BuildRelease].NET代码静态检测FxCop
    Ant高级task
    Jenkins master在windows上安装
    Jenkins的Windows Slave的配置
    Jenkins的配置
    [BuildRelease]跨平台build脚本
    使用Synergy多台电脑共享键盘鼠标和剪贴板
  • 原文地址:https://www.cnblogs.com/luyuwei/p/3615266.html
Copyright © 2020-2023  润新知