字段设置 auto_increment 属性

解决方案 »

  1.   

    每访问一次该字段,字段值就加1
    用php很容易实现的喔update tb_name set click=click+1
      

  2.   

    create table abc(id int(10) not null auto_incremnet primary key,
                     name varchar(10) not null,
                     address varchar(200) not null,
                     postcode char(6) not null
                     );
    这样就创建了一个表,这个表的id子段是自动增长的。你还可以在一建好的表中增加这样的字段,操作如下:
    alter table tb_name add id int(10) not null auto_increment first;
    或者
    alter table tb_name add id int(10) not null auto_increment;
      

  3.   

    我好象没说清楚,我的意思是不用mysql自带的自增长属性,而是自已来控制id字段的增长,问题是我取得一张表的最大id后,在+1插入表的过程中如果有其他的用户也读取了该表的最大id并也+1插入该表时就会产生同一id值的两条记录,所以必须在一个用户进行该操作时锁定该表,现在不知道如何去锁定mysql的表或记录?