Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

create table if not exists?

Hans MüllerApr 15 2015 — edited Apr 15 2015

I need to execute a script, which includes create table's and some insert into this table, but it fails after second execution because of table exists.

Is there a way to have a command like .., create table if not exists.., which dont give me error messages after second execution?

CREATE TABLE BREND

(

  ID   VARCHAR2(10) PRIMARY KEY NOT NULL,

  NAME VARCHAR2(100)            NOT NULL

);

INSERT INTO BREND (ID, NAME) VALUES ('1', 'o2');

CREATE TABLE USER_BREND

(

  "USER_ID" NUMBER(19,0) NOT NULL ENABLE,

  "BREND_ID" VARCHAR2(10) NOT NULL ENABLE,

  CONSTRAINT "USER_BREND_PK" PRIMARY KEY ("USER_ID", "BREND_ID"),

  CONSTRAINT "USER_BREND_USER_FK" FOREIGN KEY ("USER_ID")

  REFERENCES "USER" ("ID") ON DELETE CASCADE ENABLE,

  CONSTRAINT "USER_BREND_BREND_FK" FOREIGN KEY ("BREND_ID")

  REFERENCES "BREND" ("ID") ON DELETE CASCADE ENABLE

);

COMMENT ON COLUMN "USER_BREND"."USER_ID" IS 'Foreign key for the associated user';

COMMENT ON COLUMN "USER_BREND"."BREND_ID" IS 'Foreign key for the associated brend';

INSERT INTO "USER_BREND" (SELECT ID as USER_ID, '1' as BREND_ID FROM USER")

This post has been answered by caadecarvalho on Apr 15 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 13 2015
Added on Apr 15 2015
32 comments
50,763 views