zoukankan      html  css  js  c++  java
  • mysql表管理

     4.1 查看所有表

    查看所有表语句:

    show tables;

    例:

    mysql> show tables;

    +-----------------+

    | Tables_in_emp |

    +-----------------+

    | student         |

    +-----------------+

    1 row in set (0.00 sec)

                    4.2 创建表

    创建表语句:

    CREATE TABLE table_name

    (

             field1  datatype,

             field2  datatype,

             field3  datatype

    )

    --field:指定列名 datatype:指定列类型

    注意(创建表前,要先使用use db语句使用库)

    例:

    mysql> create table student[A1] (

        -> sid[A2]  int[A3] ,

        -> sname varchar(20)[A4] ,

        -> sage int

        -> );

    Query OK, 0 rows affected (0.01 sec)

                   4.3 查看表结构          

    mysql> desc student;

    +-------+-------------+------+-----+---------+-------+

    | Field | Type        | Null | Key | Default | Extra |

    +-------+-------------+------+-----+---------+-------+

    | sid   | int(11)     | YES  |     | NULL    |       |

    | sname | varchar(20) | YES  |     | NULL    |       |

    | sage  | int(11)     | YES  |     | NULL    |       |

    +-------+-------------+------+-----+---------+-------+

    3 rows in set (0.01 sec)

                         4.4 删除表

                                        

    mysql> drop table student;

    Query OK, 0 rows affected (0.01 sec)

    4.5 修改表

    1)添加字段

                                        

    mysql> alter table student add column sgender varchar(2);

    Query OK, 0 rows affected (0.03 sec)

    Records: 0  Duplicates: 0  Warnings: 0

    2)

                       删除字段                  

    mysql> alter table student drop column sgender;

    Query OK, 0 rows affected (0.03 sec)

    Records: 0  Duplicates: 0  Warnings: 0

    3)修改字段类型

                                        

    mysql> alter table student modify column remark varchar(100);

    Query OK, 0 rows affected (0.07 sec)

    Records: 0  Duplicates: 0  Warnings: 0

    4)修改字段名称

                                        

    mysql> alter table student change column sgender gender varchar(2);

    Query OK, 0 rows affected (0.03 sec)

    Records: 0  Duplicates: 0  Warnings: 0

    5)修改表名称

                                        

    mysql> alter table student rename to teacher;

    Query OK, 0 rows affected (0.01 sec)

  • 相关阅读:
    推荐体系算法总结
    Springboot 多模块调用,找不到注入的类
    LRU算法
    在SQLServer中连接另一个SQLServer库数据,在Oracle中连接另一个Oracle库数据,在SQL Server中连接Oracle数据,在Oracle中连接SQL Server数据
    用C#实现木马程序
    CSS filter 滤镜可视化配置
    微信小程序农历日期选择器 lunarpicker
    ms Sql 数据库出现 “提供的统计信息流已损坏”的解决办法。
    自制《要塞:十字军东征》无限金钱修改器
    c#+Winform实现自定义的“复制、粘贴”右键快捷菜单,多个控件共享使用一个右键菜单。
  • 原文地址:https://www.cnblogs.com/gaowc/p/9950424.html
Copyright © 2011-2022 走看看