那比如我上表中的id自增列能不能通过语句把AUTO_INCREMENT去掉,让它不是自增列,或者怎么能让自增列ID值增加到一定的数之后,我又让ID种子从1开始增加呢?

解决方案 »

  1.   

    去掉auto_increment可以用alter命令。
      

  2.   

    create table (id int AUTO_INCREMENT primary key,Mydate datetime default now())出错是因为你没有指定表格名称。
      

  3.   

    即使他指定表名,这个语句还是错误的!
    有些东西不是想当然的可以做到的,default 后面要使用常量,而不能使用函数或者表达式。
    看看手册吧。
    The DEFAULT clause specifies a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column as of MySQL 4.1.2.
      

  4.   

    楼主的第二个问题。
    楼主是不是希望id成为这种样子?
    1
    2
    3
    1
    2
    3
    ……
    如果是这样,不能用auto_increment,用alter table命令去掉它。
    然后,这个字段你不能使用 primary key(auto_increment 用这个) 或者 unique 之类的唯一索引,否则,mysql是不允许你插入一样的记录(就是说你第二个“1”是无法添加到数据库中的)。
    所以,这个字段的插入和判断应该要用程序来控制了。