1
I am beginner in the use of Oracle
, wore the firebird
before. I’d like to know, why I can’t create multiple tables at once in the SQLdeveloper
. It creates only the first table (Country).
I try to run the following instructions, to create all tables at once. (in this case I’m using only 3 tables to not get too long).
CREATE TABLE PAIS
(
IdPais INTEGER NOT NULL,
NomePais VARCHAR(60) NOT NULL,
SiglaPais VARCHAR(3) NOT NULL,
StatusPais CHAR(1) NOT NULL
);
ALTER TABLE PAIS ADD
(
CONSTRAINT PAIS PRIMARY KEY (IdPais)
);
CREATE SEQUENCE SEQ_ID_PAIS
MINVALUE 1
MAXVALUE 9999999999
START WITH 1
INCREMENT BY 1
NOCACHE
CYCLE;
CREATE OR REPLACE TRIGGER TRG_ID_PAIS BEFORE INSERT ON PAIS FOR EACH ROW BEGIN <<COLUMN_SEQUENCES>> BEGIN IF :NEW.IDPAIS IS NULL THEN SELECT SEQ_ID_PAIS.NEXTVAL INTO :NEW.IDPAIS FROM DUAL; END IF; END COLUMN_SEQUENCES; END;
CREATE TABLE ESTADO
(
IdEstado INTEGER NOT NULL,
IdPais INTEGER NOT NULL,
NomeEstado VARCHAR(60) NOT NULL,
SiglaEstado VARCHAR(2) NOT NULL,
StatusEstado CHAR(1) NOT NULL
);
ALTER TABLE ESTADO ADD
(
CONSTRAINT ESTADO PRIMARY KEY (IdEstado)
);
CREATE SEQUENCE SEQ_ID_ESTADO
MINVALUE 1
MAXVALUE 9999999999
START WITH 1
INCREMENT BY 1
NOCACHE
CYCLE;
CREATE OR REPLACE TRIGGER TRG_ID_ESTADO BEFORE INSERT ON ESTADO FOR EACH ROW BEGIN <<COLUMN_SEQUENCES>> BEGIN IF :NEW.IDESTADO IS NULL THEN SELECT SEQ_ID_ESTADO.NEXTVAL INTO :NEW.IDESTADO FROM DUAL; END IF; END COLUMN_SEQUENCES; END;
CREATE TABLE CIDADE
(
IdCidade INTEGER NOT NULL,
IdEstado INTEGER NOT NULL,
NomeCidade VARCHAR(60) NOT NULL,
StatusCidade CHAR(1) NOT NULL
);
ALTER TABLE CIDADE ADD
(
CONSTRAINT CIDADE PRIMARY KEY (IdCidade)
);
CREATE SEQUENCE SEQ_ID_CIDADE
MINVALUE 1
MAXVALUE 9999999999
START WITH 1
INCREMENT BY 1
NOCACHE
CYCLE;
CREATE OR REPLACE TRIGGER TRG_ID_CIDADE BEFORE INSERT ON CIDADE FOR EACH ROW BEGIN <<COLUMN_SEQUENCES>> BEGIN IF :NEW.IDCIDADE IS NULL THEN SELECT SEQ_ID_CIDADE.NEXTVAL INTO :NEW.IDCIDADE FROM DUAL; END IF; END COLUMN_SEQUENCES; END;
You are running as script?
– Reginaldo Rigo
@Reginaldorigo yes, I am ! (in the SQL spreadsheet - alt+F10)
– AlunoOracle
try to put under each command the bar
/
and forehead– adventistaam
@adventistaam as well, the bar ? Where to put and what the purpose ?
– AlunoOracle
I do it in mine and it works rsrs, it’s like a delimiter of each command
– adventistaam
@adventist, right, more where I place specifically ?
– AlunoOracle
as @adventistaam indicated, place a bar at the end of each create. ex: create table test(id number); / create table teste2(id number);
– Renato Afonso
@Renatoafonso Right, but it just works by creating the table. It just worked by leaving the CREATE TABLE. If I’m going to use it the way it is in my script it doesn’t run ! For the creation of SEQUENCE and TRIGGER together the tables did not work. (I tried to add to the end of each semicolon also to test, and it did not help)
– AlunoOracle