• MySql处理数据库和表


    show databases;

    mysql> show databases;


    mysql> create database db_test;
    Query OK, 1 row affected (0.00 sec)


    use

    mysql> use db_test;
    Database changed


    mysqldrop

    mysql> drop database db_test;
    Query OK, 0 rows affected (0.00 sec)

     

    MySQL


    create table

    mysql> create table tb_test(
        -> id int unsigned not null auto_increment,
        -> firstname varchar(25) not null,
        -> lastname varchar(25) not null,
        -> email varchar(45) not null,
        -> phone varchar(10) not null,
        -> primary key(id));
    Query OK, 0 rows affected (0.03 sec)

    mysql> create table db_test.tb_test(
        -> id int unsigned not null auto_increment,
        -> firstname varchar(25) not null,
        -> lastname varchar(25) not null,
        -> email varchar(45) not null,
        -> phone varchar(10) not null,
        -> primary key(id));
    Query OK, 0 rows affected (0.03 sec)


    MySQLcreate table

    mysql> create table if not exists db_test.tb_test(
        -> id int unsigned not null auto_increment,
        -> firstname varchar(25) not null,
        -> lastname varchar(25) not null,
        -> email varchar(45) not null,
        -> phone varchar(10) not null,
        -> primary key(id));
    Query OK, 0 rows affected, 1 warning (0.00 sec)

    Query OK


    tb_testtb_test2:

    mysql> create table tb_test2 select * from db_test.tb_test;
    Query OK, 0 rows affected (0.03 sec)
    Records: 0  Duplicates: 0  Warnings: 0

    tb_test2

    create select

    mysql> describe tb_test;
    +-----------+------------------+------+-----+---------+----------------+
    | Field     | Type             | Null | Key | Default | Extra          |
    +-----------+------------------+------+-----+---------+----------------+
    | id        | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | firstname | varchar(25)      | NO   |     | NULL    |                |
    | lastname  | varchar(25)      | NO   |     | NULL    |                |
    | email     | varchar(45)      | NO   |     | NULL    |                |
    | phone     | varchar(10)      | NO   |     | NULL    |                |
    +-----------+------------------+------+-----+---------+----------------+
    5 rows in set (0.01 sec)
    mysql> create table tb_test2 select id, firstname, lastname, email from tb_test;
    Query OK, 0 rows affected (0.03 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    mysql> describe tb_test2;
    +-----------+------------------+------+-----+---------+-------+
    | Field     | Type             | Null | Key | Default | Extra |
    +-----------+------------------+------+-----+---------+-------+
    | id        | int(10) unsigned | NO   |     | 0       |       |
    | firstname | varchar(25)      | NO   |     | NULL    |       |
    | lastname  | varchar(25)      | NO   |     | NULL    |       |
    | email     | varchar(45)      | NO   |     | NULL    |       |
    +-----------+------------------+------+-----+---------+-------+
    4 rows in set (0.01 sec)


    MySQL

    temporarycreate table

    mysql> create temporary table emp_temp select firstname, lastname from tb_test;
    Query OK, 0 rows affected (0.02 sec)
    Records: 0  Duplicates: 0  Warnings: 0

    MySQLMySQLdrop table


    show tables

    mysql> show tables;
    +-------------------+
    | Tables_in_db_test |
    +-------------------+
    | tb_test           |
    | tb_test2          |
    +-------------------+
    2 rows in set (0.00 sec)


    describe

    mysql> describe tb_test;
    +-----------+------------------+------+-----+---------+----------------+
    | Field     | Type             | Null | Key | Default | Extra          |
    +-----------+------------------+------+-----+---------+----------------+
    | id        | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | firstname | varchar(25)      | NO   |     | NULL    |                |
    | lastname  | varchar(25)      | NO   |     | NULL    |                |
    | email     | varchar(45)      | NO   |     | NULL    |                |
    | phone     | varchar(10)      | NO   |     | NULL    |                |
    +-----------+------------------+------+-----+---------+----------------+
    5 rows in set (0.00 sec)

    show

    mysql> show columns in tb_test;
    +-----------+------------------+------+-----+---------+----------------+
    | Field     | Type             | Null | Key | Default | Extra          |
    +-----------+------------------+------+-----+---------+----------------+
    | id        | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | firstname | varchar(25)      | NO   |     | NULL    |                |
    | lastname  | varchar(25)      | NO   |     | NULL    |                |
    | email     | varchar(45)      | NO   |     | NULL    |                |
    | phone     | varchar(10)      | NO   |     | NULL    |                |
    +-----------+------------------+------+-----+---------+----------------+
    5 rows in set (0.00 sec)


    drop table

    drop [temporary] table [if exists] tbl_name [, tbl_name, ...]


    alter

    create tablealter tabletb_demoemail

    mysql> alter table tb_demo add column email varchar(45);
    Query OK, 0 rows affected (0.14 sec)
    Records: 0  Duplicates: 0  Warnings: 0

    firstafterlast

    emailnot null

    mysql> alter table tb_demo change email email varchar(45) not null;
    Query OK, 0 rows affected (0.11 sec)
    Records: 0  Duplicates: 0  Warnings: 0

    email

    mysql> alter table tb_demo drop email;
    Query OK, 0 rows affected (0.09 sec)
    Records: 0  Duplicates: 0  Warnings: 0
  • 相关阅读:
    iostream、printf/wprintf和中文输出【转】
    java命令行运行错误:ClassNotFoundException【转】
    一致性代码段和非一致性代码段【转】
    Winform disign tips(转)
    WinForm下多层架构的实现(转)
    如何在GPU上产生随机数
    最快速度找到内存泄漏
    给定单链表的头结点,如何快速的找到倒数的第n个节点?
    DX11_基于GPU_GeometryShader的3D精确拾取
    Directx11:基于GPU_GeometryShader的Billboard公告板绘制
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4557752.html
Copyright © 2020-2023  润新知