用什么办法可以实现表主键
p001
p002
p003
p004的增长,写一个函数,还是过程来实现那?怎么编?

解决方案 »

  1.   

    表主键
    定为 1,2,3  N
    显示的时候
    select p+right(id+1000,3)
    == 思想重于技巧 ==
      

  2.   

    你确定都是'p' + 001, 002, ... 999的这种模式吗?不知道下边是不是你想要的?
    mysql> create table t3(fid int(3) zerofill not null auto_increment primary key,
    col2 varchar(32));
    Query OK, 0 rows affected (0.08 sec)mysql> insert into t3 values(null, 'iihero');
    Query OK, 1 row affected (0.03 sec)mysql> insert into t3 values(null, 'iihero1');
    Query OK, 1 row affected (0.03 sec)mysql> insert into t3 values(null, 'iihero3');
    Query OK, 1 row affected (0.08 sec)mysql> select concat('p', fid), col2 from t3;
    +------------------+---------+
    | concat('p', fid) | col2    |
    +------------------+---------+
    | p001             | iihero  |
    | p002             | iihero1 |
    | p003             | iihero3 |
    +------------------+---------+
    3 rows in set (0.00 sec)
      

  3.   

    create table t3(fid int(3) zerofill not null auto_increment primary key, 
    col2 varchar(32);
    中的zerofill是什么意思?
    为什么就只是001三位那,那他自动增加到999以后还会增加吗?
      

  4.   

    int(4)可以到9999
    int(10)可以到9999999999