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;

  • 相关阅读:
    android开发 退出程序
    armeabi和armeabi-v7a引起的问题
    我的博客
    第二章 应用层(一) 应用层概览
    第一章 计算机网络和因特网
    Linux学习笔记——第一篇——Ubuntu安装与操作
    怒学Python——完结篇——I/O
    怒学Python——第四篇——函数与模块
    怒学Python——第三篇——结构控制
    怒学Python——第二篇——类型与运算
  • 原文地址:https://www.cnblogs.com/avivaye/p/2773479.html
Copyright © 2011-2022 走看看