zoukankan      html  css  js  c++  java
  • mysql中的enum型

    enum设置后

    值只能是给出的值中的其中一个

    mysql> create table enum(e enum('1','2','3','4','5','6','7','8','9','10'));
    Query OK, 0 rows affected (0.03 sec)
    
    mysql> desc enum;
    +-------+------------------------------------------------+------+-----+---------
    +-------+
    | Field | Type                                           | Null | Key | Default
    | Extra |
    +-------+------------------------------------------------+------+-----+---------
    +-------+
    | e     | enum('1','2','3','4','5','6','7','8','9','10') | YES  |     | NULL
    |       |
    +-------+------------------------------------------------+------+-----+---------
    +-------+
    1 row in set (0.00 sec)
    
    mysql> insert into enum values(1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> insert into enum values(11);
    Query OK, 1 row affected, 1 warning (0.00 sec)
    
    mysql> select * from enum;
    +------+
    | e    |
    +------+
    | 1    |
    |      |
    +------+
    2 rows in set (0.00 sec)
    
    mysql> insert into enum values(8);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from enum;
    +------+
    | e    |
    +------+
    | 1    |
    |      |
    | 8    |
    +------+
    3 rows in set (0.00 sec)
    
    mysql>
    

     当值 不存在enum中时, 会返回默认的值 , 也就是default中的值。

    mysql> create table enum1(e enum('1','2','3','4','5','6','7','8','9','10') not n
    ull default '11');
    ERROR 1067 (42000): Invalid default value for 'e'
    mysql> create table enum1(e enum('1','2','3','4','5','6','7','8','9','10') not n
    ull default 10);
    Query OK, 0 rows affected (0.03 sec)
    
    mysql> desc enum1;
    +-------+------------------------------------------------+------+-----+---------
    +-------+
    | Field | Type                                           | Null | Key | Default
    | Extra |
    +-------+------------------------------------------------+------+-----+---------
    +-------+
    | e     | enum('1','2','3','4','5','6','7','8','9','10') | NO   |     | 10
    |       |
    +-------+------------------------------------------------+------+-----+---------
    +-------+
    1 row in set (0.00 sec)
    
    mysql>
    
  • 相关阅读:
    C++编程中的小规范(转)
    windows的消息大全(收集)
    C中的一些好玩的事(一)转
    C++ 温故而知新(三)
    C++温故而知新(二)
    C++的内存分布(一)转
    C++ 温故而知新(一)
    C++反射机制模拟
    VS2010 下配置opeNGL遇到的问题
    SharedPreference.Editor的apply和commit方法异同
  • 原文地址:https://www.cnblogs.com/perl6/p/7057615.html
Copyright © 2011-2022 走看看