![create or replace table on replace values](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisuIXN-tSxhiA8PDIbVd9Uz4H-CLs4rePo-U-McWOcMMD-mAdXHYzhk4EKZl8OR0ByCY_2TCTXiUuCJrg9bZcYgf7pksXa3l0HpoUIFioUmwvmG2jnd_HmEvxnZ7Kf2m74QbI7lRFkGhlh/s200/sql.png)
In previous posts I have given examples of using the CREATE OR REPLACE for all kinds of SQL objects: Views, Indexes, Functions, Triggers, Sequences, etc. One situation I have not mentioned is using this option when creating a Table. I know it sounds a bit scary to replace an existing Table that contains data. If I am going to do it I want to have the option to preserve the data or to delete it.
Creating a new table is as easy as:
01 CREATE TABLE MYLIB.TESTING_TABLE 02 FOR SYSTEM NAME "TESTTABLE" 03 ( 04 FIRST_COLUMN FOR "FIRST" VARCHAR(10) NOT NULL, 05 IDENTITY_COLUMN FOR "ID_COL" BIGINT 06 GENERATED ALWAYS AS IDENTITY 07 ) ; 08 INSERT INTO MYLIB.TESTTABLE (FIRST_COLUMN) 09 VALUES('FIRST'),('SECOND'),('THIRD') ; |