Search notes:

SQLite: alter table

The alter table statement can be used to
It is especially noteworthy that alter table cannot be used to add constraints, such as primary or foreign keys, that is, there is no alter table … add constraint clause.
The reason for this shortcoming is that the definition of the database's schema is stored as sql statement text in the internal table sqlite_master and it is somewhat difficult to modify the stored statements' text in that table.

Rename a table

create table tq84_orig (
  col_1 primary key,
  col_2   not null,
  col_3   not null,
  col_4,
  --
  unique(col_2, col_3)
);

begin transaction;

insert into tq84_orig values (1, 'abc', 'def', 'ghi');
insert into tq84_orig values (2, 'jkl', 'mno',  null);

commit transaction;

alter table tq84_orig rename to tq84_renamed;

.tables
--
-- tq84_renamed

.schema tq84_renamed
--
-- CREATE TABLE "tq84_renamed" (
--   col_1 primary key,
--   col_2   not null,
--   col_3   not null,
--   col_4,
--   --
--   unique(col_2, col_3)
-- );

select * from tq84_renamed;
--
--1|abc|def|ghi
--2|jkl|mno|

drop table tq84_renamed;
Github repository about-sqlite, path: /tables/alter/rename-to.sql

See also

table

Index