DROP TABLE IF EXISTS customer;
CREATE TABLE customer (
  Cust_id int(4) NOT NULL AUTO_INCREMENT,
  Cust_Name varchar(20) NOT NULL UNIQUE,
  Cust_Tel varchar(20),
  Cust_CompanyName varchar(50),
  Cust_Address1 varchar(150),
  Cust_Address2 varchar(150),
  Cust_Address3 varchar(150),
  Cust_PostCode varchar(20),
  Cust_Level int(4),
  PRIMARY KEY (Cust_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
本人以前都是用MSSQL的,用Mysql真的有点不习惯.Cust_id为自动递增列,但是却不想设置为主键.这列也不想删除,也是希望尽量保持与MSSQL一致的表结构.
有点费神,望大家指点一下,都有什么方法可以解决.

解决方案 »

  1.   

    设置成普通keymysql>  create table test3(a int not null auto_increment,b int ,key(a));
    ERROR 1050 (42S01): Table 'test3' already exists
    mysql>  create table testauto(a int not null auto_increment,b int ,key(a));
    Query OK, 0 rows affected (0.02 sec)mysql> insert into testauto(b) values(1);
    Query OK, 1 row affected (0.00 sec)mysql> insert into testauto(b) values(1);
    Query OK, 1 row affected (0.00 sec)mysql> insert into testauto(b) values(1);
    Query OK, 1 row affected (0.00 sec)mysql> select * from testauto;
    +---+------+
    | a | b    |
    +---+------+
    | 1 |    1 |
    | 2 |    1 |
    | 3 |    1 |
    +---+------+
    3 rows in set (0.00 sec)
      

  2.   

    Quote: 引用 1 楼 rucypli 的回复:

    你的Sql里,a还是主键..............好像有点答非所问..........如果不设置主键,也可以自动递增吗?
      

  3.   

    谢谢兄台,我明白了
    DROP TABLE IF EXISTS testauto;
    create table testauto(
    a int not null auto_increment,
    b int,
    key(a),
    PRIMARY KEY (b)
    );
    insert into testauto(b) values(1);
    insert into testauto(b) values(2);
    SELECT * FROM testauto;
    原来还有key ,primary key的差别.