Altering SQLite column type and adding PK constraint

前端 未结 3 1792
隐瞒了意图╮
隐瞒了意图╮ 2021-02-05 19:32

How to change the type of a column in a SQLite table?

I\'ve got:

    CREATE TABLE table(
        id INTEGER,
        salt TEXT NOT NULL UNIQUE,
        s         


        
3条回答
  •  囚心锁ツ
    2021-02-05 20:04

    Since RDBMS is not specified, these are DB2 queries:

    1. Make ID as primary key:

      ALTER TABLE table
          ADD CONSTRAINT pk_id
          PRIMARY KEY (id)
    2. Make salt as not UNIQUE:

      ALTER TABLE table
          DROP UNIQUE 
    3. Make salt nullable:

      ALTER TABLE table
          ALTER COLUMN salt DROP NOT NULL

    You will need to do a reorg after drop not null. This is to be done from the command prompt.

    reorg table 
    

提交回复
热议问题