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>
    
  • 相关阅读:
    【z02】选择客栈
    JavaEE(22)
    驱动表问题
    影响子查询展开的情况
    SQL*Net message from client
    等值链接和非等值链接
    ||拼接列关联和直接关联区别
    分页SQL优化
    SQL*Net more data to client
    SQL*Net message to client
  • 原文地址:https://www.cnblogs.com/perl6/p/7057615.html
Copyright © 2011-2022 走看看