i want to replace an existing table with a new one, without losing foreign keys or inheritance relations. But I feel lazy to alter it to make it look like the new one. Is there a way to replace the table without doing all the hard job? Like a CREATE OR REPLACE statement in SQLITE or by tweaking the table name in pg_class table?
CREATE TABLE a (
id serial NOT NULL,
-- a bunch of other columns
CONSTRAINT a_pk PRIMARY KEY(a)
);
CREATE TABLE b (
id serial NOT NULL,
a_id bigint refernces a(id)
);
--REPLACE a with a new table without violating b FOREIGN KEY relations(somehow)
CREATE OR REPLACE a(
id serial NOT NULL,
-- a bunch of new columns
CONSTRAINT a_pk PRIMARY KEY(a)
);
ALTER TABLE
?create or replace table
in any other DBMS (Oracle, SQL Server, DB2, Firebird, HSQLDB, ....)create or replace
a table with ablah varchar(8)
column and the replacement has ablah integer
column, what happens? Does it assume that since they're the same name you want to try to coerce the data?