代码之家  ›  专栏  ›  技术社区  ›  Stephane

如何删除序列?

  •  1
  • Stephane  · 技术社区  · 6 年前

    低于 mariadb-10.3.7 在InnoDB引擎上,我尝试使用以下结构:

    drop sequence if exists user_account_id_seq;
    create sequence user_account_id_seq start with 1 increment by 10;
    drop table if exists user_account;
    create table user_account (
      -- id bigint(20) unsigned not null auto_increment,
      id bigint(20) unsigned not null default (next value for user_account_id_seq),
      version int(10) unsigned not null,
      created_on datetime,
      updated_on datetime,
      firstname varchar(255) not null,
      lastname varchar(255) not null,
      password varchar(100),
      password_salt varchar(50),
      readable_password varchar(50),
      email varchar(50) not null,
      confirmed_email bit(1) not null check (confirmed_email in (0, 1)),
      work_phone varchar(20),
      unique key email (email),
      primary key (id)
    );
    

    但它不想删除一个序列:

    --------------
    drop sequence if exists user_account_id_seq
    --------------
    
    --------------
    commit
    --------------
    
    --------------
    create sequence user_account_id_seq start with 1 increment by 10
    --------------
    
    ERROR 1050 (42S01) at line 4: Table '`useraccount`.`user_account_id_seq`' already exists
    + /usr/bin/mariadb/install/bin/mysql useraccount --protocol=tcp -h mysql -P 3306 -u root -v
    --------------
    

    MariaDB [useraccount]> create sequence user_account_id_seq start with 1 increment by 10;
    ERROR 1813 (HY000): Tablespace for table '`useraccount`.`user_account_id_seq`' exists. Please DISCARD the tablespace before IMPORT
    MariaDB [useraccount]> alter table `useraccount`.`user_account_id_seq` discard tablespace; 
    ERROR 1146 (42S02): Table 'useraccount.user_account_id_seq' doesn't exist
    
    0 回复  |  直到 6 年前