zoukankan      html  css  js  c++  java
  • [mysql] 常用命令四

    ① 查看表的创建细节

     mysql>show create table employee;

     user  | CREATE TABLE `user` (
     `id` int(11) NOT NULL AUTO_INCREMENT,
     `name` varchar(30) NOT NULL,
     `password` varchar(32) NOT NULL,
     `age` int(11) NOT NULL,
     `sex` varchar(2) DEFAULT '男'?,
     `birthday` date DEFAULT NULL,
     PRIMARY KEY (`id`)
     ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=gbk

    ② 表名的修改
    mysql> rename table userclob to userclob1;
    Query OK, 0 rows affected (0.15 sec)

    ③ 在表现有列的基础上增加一列。
    alter table 表名add 列名 字段数据类型;

    mysql> alter table userclob add image blob;
    Query OK, 7 rows affected (0.27 sec)
    Records: 7  Duplicates: 0  Warnings: 0

    mysql> desc userclob;
    +-------+-------------+------+-----+---------+----------------+
    | Field | Type        | Null | Key | Default | Extra          |
    +-------+-------------+------+-----+---------+----------------+
    | id    | int(11)     | NO   | PRI | NULL    | auto_increment |
    | name  | varchar(30) | NO   |     | NULL    |                |
    | note  | longtext    | YES  |     | NULL    |                |
    | image | blob        | YES  |     | NULL    |                |
    +-------+-------------+------+-----+---------+----------------+
    4 rows in set (0.01 sec)

    ④ 修改name列,使其长度为60。

    mysql> alter table userclob modify name varchar(60);
    Query OK, 7 rows affected (0.42 sec)
    Records: 7  Duplicates: 0  Warnings: 0

    mysql> desc userclob;
    +-------+-------------+------+-----+---------+----------------+
    | Field | Type        | Null | Key | Default | Extra          |
    +-------+-------------+------+-----+---------+----------------+
    | id    | int(11)     | NO   | PRI | NULL    | auto_increment |
    | name  | varchar(60) | YES  |     | NULL    |                |
    | note  | longtext    | YES  |     | NULL    |                |
    | image | blob        | YES  |     | NULL    |                |
    +-------+-------------+------+-----+---------+----------------+
    4 rows in set (0.01 sec)

    ⑤ 删除image列
    mysql> alter table userclob drop image;
    Query OK, 7 rows affected (0.30 sec)
    Records: 7  Duplicates: 0  Warnings: 0

    mysql> desc userclob;
    +-------+-------------+------+-----+---------+----------------+
    | Field | Type        | Null | Key | Default | Extra          |
    +-------+-------------+------+-----+---------+----------------+
    | id    | int(11)     | NO   | PRI | NULL    | auto_increment |
    | name  | varchar(60) | YES  |     | NULL    |                |
    | note  | longtext    | YES  |     | NULL    |                |
    +-------+-------------+------+-----+---------+----------------+
    3 rows in set (0.01 sec)

    ⑥ 列名的修改
    mysql> desc userclob;
    +-------+-------------+------+-----+---------+----------------+
    | Field | Type        | Null | Key | Default | Extra          |
    +-------+-------------+------+-----+---------+----------------+
    | id    | int(11)     | NO   | PRI | NULL    | auto_increment |
    | name  | varchar(60) | YES  |     | NULL    |                |
    | note  | longtext    | YES  |     | NULL    |                |
    +-------+-------------+------+-----+---------+----------------+
    3 rows in set (0.01 sec)

    mysql> alter table userclob change id userid int;
    Query OK, 7 rows affected (0.30 sec)
    Records: 7  Duplicates: 0  Warnings: 0

    mysql> desc userclob;
    +--------+-------------+------+-----+---------+-------+
    | Field  | Type        | Null | Key | Default | Extra |
    +--------+-------------+------+-----+---------+-------+
    | userid | int(11)     | NO   | PRI | 0       |       |
    | name   | varchar(60) | YES  |     | NULL    |       |
    | note   | longtext    | YES  |     | NULL    |       |
    +--------+-------------+------+-----+---------+-------+
    3 rows in set (0.01 sec)

    ⑦ 使用truncate删除表中记录。
    truncate table employee;

  • 相关阅读:
    alkhaser学习笔记(一)Anti Debug
    8086 汇编指令手册查询(转)
    QueryUserAPC Ring3下 APC注入
    内存分配(malloc,new,VirtualAlloc,HeapAlloc,GlobalAlloc,LocalAlloc)区别与注意
    error C2220: 警告被视为错误 没有生成“object”文件 (转)
    消息队列
    分页存储过程(对有主键的表效率极高)
    asp.net vs2010 设计报表rdlc时,未能加载文件或程序集
    【翻译】创建ViewState特征的自动ViewState属性
    中英文字符的截取
  • 原文地址:https://www.cnblogs.com/avivaye/p/2773479.html
Copyright © 2011-2022 走看看