• 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
  • 相关阅读:
    ASP.NET结合COM组件发送Email
    木马生成技术
    AJAX中使用Session
    对象模型文档对象模型DOM简介
    何遍历数据源中的表名称
    AJAX.NET用户开发指南
    用ASP.NET上传大文件
    .net反编译利器
    Equals和GetHashcode
    Factory Method模式
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4557752.html
Copyright © 2020-2023  润新知