zoukankan      html  css  js  c++  java
  • MySQL-SQL基础

    mysql> use test;
    Database changed
    mysql> create table emp(ename varchar(10),hirdate date,sal decimal(10,2),deptno int(2));
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> show tables;
    +----------------+
    | Tables_in_test |
    +----------------+
    | emp            |
    +----------------+
    1 row in set (0.00 sec)
    
    mysql> desc emp;
    +---------+---------------+------+-----+---------+-------+
    | Field   | Type          | Null | Key | Default | Extra |
    +---------+---------------+------+-----+---------+-------+
    | ename   | varchar(10)   | YES  |     | NULL    |       |
    | hirdate | date          | YES  |     | NULL    |       |
    | sal     | decimal(10,2) | YES  |     | NULL    |       |
    | deptno  | int(2)        | YES  |     | NULL    |       |
    +---------+---------------+------+-----+---------+-------+
    4 rows in set (0.00 sec)
    
    mysql> show create table empG
    *************************** 1. row ***************************
           Table: emp
    Create Table: CREATE TABLE `emp` (
      `ename` varchar(10) DEFAULT NULL,
      `hirdate` date DEFAULT NULL,
      `sal` decimal(10,2) DEFAULT NULL,
      `deptno` int(2) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    1 row in set (0.00 sec)
    
    mysql> alter table emp modify ename varchar(20);
    Query OK, 0 rows affected (0.01 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> desc emp;
    +---------+---------------+------+-----+---------+-------+
    | Field   | Type          | Null | Key | Default | Extra |
    +---------+---------------+------+-----+---------+-------+
    | ename   | varchar(20)   | YES  |     | NULL    |       |
    | hirdate | date          | YES  |     | NULL    |       |
    | sal     | decimal(10,2) | YES  |     | NULL    |       |
    | deptno  | int(2)        | YES  |     | NULL    |       |
    +---------+---------------+------+-----+---------+-------+
    4 rows in set (0.00 sec)
    
    mysql> alter table emp add column age int(3);
    Query OK, 0 rows affected (0.02 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> desc emp;
    +---------+---------------+------+-----+---------+-------+
    | Field   | Type          | Null | Key | Default | Extra |
    +---------+---------------+------+-----+---------+-------+
    | ename   | varchar(20)   | YES  |     | NULL    |       |
    | hirdate | date          | YES  |     | NULL    |       |
    | sal     | decimal(10,2) | YES  |     | NULL    |       |
    | deptno  | int(2)        | YES  |     | NULL    |       |
    | age     | int(3)        | YES  |     | NULL    |       |
    +---------+---------------+------+-----+---------+-------+
    5 rows in set (0.00 sec)
    
    mysql> alter table emp drop column age;
    Query OK, 0 rows affected (0.02 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> desc emp;
    +---------+---------------+------+-----+---------+-------+
    | Field   | Type          | Null | Key | Default | Extra |
    +---------+---------------+------+-----+---------+-------+
    | ename   | varchar(20)   | YES  |     | NULL    |       |
    | hirdate | date          | YES  |     | NULL    |       |
    | sal     | decimal(10,2) | YES  |     | NULL    |       |
    | deptno  | int(2)        | YES  |     | NULL    |       |
    +---------+---------------+------+-----+---------+-------+
    4 rows in set (0.00 sec)
    
    mysql> alter table emp add column age int(3);
    Query OK, 0 rows affected (0.01 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> alter table emp change column age age1 int(4);
    Query OK, 0 rows affected (0.01 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> desc emp;
    +---------+---------------+------+-----+---------+-------+
    | Field   | Type          | Null | Key | Default | Extra |
    +---------+---------------+------+-----+---------+-------+
    | ename   | varchar(20)   | YES  |     | NULL    |       |
    | hirdate | date          | YES  |     | NULL    |       |
    | sal     | decimal(10,2) | YES  |     | NULL    |       |
    | deptno  | int(2)        | YES  |     | NULL    |       |
    | age1    | int(4)        | YES  |     | NULL    |       |
    +---------+---------------+------+-----+---------+-------+
    5 rows in set (0.00 sec)
    
    
    mysql> alter table emp add birth date after ename;
    Query OK, 0 rows affected (0.02 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> 
    mysql> desc emp;
    +---------+---------------+------+-----+---------+-------+
    | Field   | Type          | Null | Key | Default | Extra |
    +---------+---------------+------+-----+---------+-------+
    | ename   | varchar(20)   | YES  |     | NULL    |       |
    | birth   | date          | YES  |     | NULL    |       |
    | hirdate | date          | YES  |     | NULL    |       |
    | sal     | decimal(10,2) | YES  |     | NULL    |       |
    | deptno  | int(2)        | YES  |     | NULL    |       |
    | age1    | int(4)        | YES  |     | NULL    |       |
    +---------+---------------+------+-----+---------+-------+
    6 rows in set (0.00 sec)
    
    mysql> alter table emp rename emp1;
    Query OK, 0 rows affected (0.01 sec)
    
    
    mysql> desc emp1;
    +---------+---------------+------+-----+---------+-------+
    | Field   | Type          | Null | Key | Default | Extra |
    +---------+---------------+------+-----+---------+-------+
    | ename   | varchar(20)   | YES  |     | NULL    |       |
    | birth   | date          | YES  |     | NULL    |       |
    | hirdate | date          | YES  |     | NULL    |       |
    | sal     | decimal(10,2) | YES  |     | NULL    |       |
    | deptno  | int(2)        | YES  |     | NULL    |       |
    | age1    | int(4)        | YES  |     | NULL    |       |
    +---------+---------------+------+-----+---------+-------+
    6 rows in set (0.00 sec)
    
    mysql> 
  • 相关阅读:
    软件工程第二次作业
    第一次作业
    理论物理特训-02
    左神-06 二叉树
    哲学通论之人-05(end)
    哲学通论之人-04
    左神-05 二分搜索(多看几遍)
    哲学通论之人-01
    航空母舰-04(end)
    题解 P3126 【[USACO15OPEN]回文的路径Palindromic Paths】
  • 原文地址:https://www.cnblogs.com/drizzle-xu/p/10250673.html
Copyright © 2011-2022 走看看