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> 
  • 相关阅读:
    [AGC030F] Permutation and Minimum
    nginx
    Flex建立AS项目时,如何设定发布的舞台大小
    让Flex 支持VSS
    Flex编程实用技巧
    Flash/Flex学习笔记(57):实用技巧
    sql 2000 "无法执行查询,因为一些文件缺少或未注册"的解决办法
    Flash/Flex学习笔记(56):矩阵变换
    什么是反向代理,如何利用反向代理提高网站性能
    AS3及Flex的百条常用知识
  • 原文地址:https://www.cnblogs.com/drizzle-xu/p/10250673.html
Copyright © 2011-2022 走看看