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> 
  • 相关阅读:
    js文字跳动效果
    js文字效果
    centos7安装Logwatch配合msmtp邮件客户端发送服务器监控分析日志
    子查询
    Hexo添加字数统计、阅读时长
    基于visual Studio2013解决C语言竞赛题之0523魔方阵
    基于visual Studio2013解决C语言竞赛题之0522和为素
    基于visual Studio2013解决C语言竞赛题之0521圆盘求和
    基于visual Studio2013解决C语言竞赛题之0520相邻元素
    基于visual Studio2013解决C语言竞赛题之0519最大值
  • 原文地址:https://www.cnblogs.com/drizzle-xu/p/10250673.html
Copyright © 2011-2022 走看看