zoukankan      html  css  js  c++  java
  • MySQL unique 注意

    刚才修改表结构:

     1 alter table room add CONSTRAINT roomname_unique UNIQUE(roomname); 

    结果提示如下错误:

     1 ERROR 1071 : Specified key was too long; max key length is 767 bytes 

    搞了一会没明白,上网搜了。

    原因如下:

     1 +----------+---------------+------+-----+---------+----------------+
     2 | Field    | Type          | Null | Key | Default | Extra          |
     3 +----------+---------------+------+-----+---------+----------------+
     4 | roomid   | int(10)       | NO   | PRI | NULL    | auto_increment |
     5 | roomname | varchar(1024) | NO   |     |         |                |
     6 | capacity | int(10)       | NO   |     | 8       |                |
     7 | cost     | decimal(10,0) | NO   |     | 0       |                |
     8 | count    | decimal(10,0) | NO   |     | 0       |                |
     9 | status   | int(1)        | NO   |     | 0       |                |
    10 | comment  | varchar(1024) | YES  |     |         |                |
    11 | deleted  | int(1)        | NO   |     | 1       |                |
    12 +----------+---------------+------+-----+---------+----------------+

    我的roomname字段长度设定的是varchar(1024),1024长于767bytes。

    database维护索引是需要开销的,所以数据库不会使它过大。Mysql数据库的varchar长度被限制在0~65535之间。

  • 相关阅读:
    [leetcode-91-Decode Ways]
    [leetcode-72-Edit Distance]
    [leetcode-67-Add Binary]
    [leetcode-137-Single Number II]
    [leetcode-60-Permutation Sequence]
    [leetcode-55-Jump Game]
    [leetcode-18-4Sum]
    [leetcode-15-3Sum]
    [leetcode-47-Permutations II]
    easyui tabs update 强制刷新页面
  • 原文地址:https://www.cnblogs.com/skimoon/p/3657231.html
Copyright © 2011-2022 走看看