Oracle SQL Developer Table Creation

Asked

Viewed 1,424 times

2

inserir a descrição da imagem aqui

create table socio
(
    id_socio integer Not NULL,
    nome varchar(256)  not NULL,
    cpf  varchar(11) not NULL,
    email varchar(256),
    id_situacao integer,
    constraint socio_id_socio_PK primary key(id_socio),
    constraint socio_id_situacao_FK foreign key(id_situacao) references situacao(id_situacao)
);

CREATE TABLE "SITUACAO" (
    Id_Situacao INTEGER NOT NULL,
    Situacao VARCHAR(10) NOT NULL,
    CONSTRAINT SITUACAO_ID_SITUACAO_PK PRIMARY KEY(Id_Situacao)
);

CREATE TABLE MARCA (
    Id_marca INTEGER not NULL,
    Marca VARCHAR(128) not NULL,
    CONSTRAINT MARCA_ID_MARCA_PK PRIMARY KEY(Id_marca)
);

create table CARRO -- Aqui é a  linha 24
(
    id_CARRO integer Not NULL,
    Modelo VARCHAR(128) not NULL,
    Cor VARCHAR(64) not NULL,
    placa VARCHAR(10) not NULL,
    constraint socio_id_socio_PK primary key(id_CARRO),
    constraint marca_id_marca_FK foreign key(Id_marca) references MARCA(Id_marca),
    constraint socio_id_socio_FK foreign key(id_socio) references socio(id_socio)
);
  • 1

    What a mistake you’re making?

1 answer

2


You should create tables that are used as references in foreign keys first. I suggest the following order:

CREATE TABLE situacao (
  Id_Situacao INTEGER NOT NULL,
  Situacao VARCHAR(10) NOT NULL,
  CONSTRAINT SITUACAO_ID_SITUACAO_PK PRIMARY KEY(Id_Situacao)
);

CREATE TABLE MARCA (
  Id_marca INTEGER not NULL,
  Marca VARCHAR(128) not NULL,
  CONSTRAINT MARCA_ID_MARCA_PK PRIMARY KEY(Id_marca)
);

create table socio (
  id_socio integer Not NULL,
  nome varchar(256) not NULL,
  cpf varchar(11) not NULL,
  email varchar(256),
  id_situacao integer,
  constraint socio_id_socio_PK primary key(id_socio),
  constraint socio_id_situacao_FK foreign key(id_situacao) references situacao(id_situacao)
);

create table CARRO (
  id_CARRO integer Not NULL,
  id_marca integer NOT NULL,
  id_socio integer NOT NULL,
  Modelo VARCHAR(128) not NULL,
  Cor VARCHAR(64) not NULL,
  placa VARCHAR(10) not NULL,
  constraint socio_id_socio_PK primary key(id_CARRO),
  constraint socio_id_situacao_FK foreign key(id_marca) references situacao(id_marca),
  constraint socio_id_situacao_FK foreign key(id_socio) references situacao(id_socio)
);

On the table carro you also have not created the columns that reference the other tables.

  • sORACK is GIVING THIS HERE LOOK; Error from line : 13 in command - create table socio ( id_socio integer Not NULL, name varchar(256) not NULL, Cpf varchar(11) not NULL, email varchar(256), id_situacao integer, Constraint socio_id_socio_PK Primary key(id_socio), Constraint socio_id_situaca_FK Foreign key(id_situacao) References situacao(id_situacao) ) Bug report - ORA-00942: the table or view does not exist 00942. 00000 - "table or view does not exist" *Cause: *Action:

  • @Namelessman try using the script I just posted as an answer. There were columns missing

  • Error from line : 23 on the command - create table CAR ( id_CARRO integer Not NULL, Model VARCHAR(128) not NULL, Color VARCHAR(64) not NULL, plate VARCHAR(10) not NULL, Constraint socio_id_socio_PK Primary key(id_CARRO), Constraint socio_id_situacao_FK Foreign key(id_brand) Different situation(id_brand), Constraint socio_id_situacao_FK Foreign key(id_socio) Different situation(id_socio) ) Bug report - ORA-00904: "ID_MARCA": invalid identifier 00904. 00000 - "%s: invalid Identifier" *Cause: *Action:

  • @Namelessman yes, I fixed it with the last edit. Test with the current code

  • Error from line : 23 on command - create table CAR (......

Browser other questions tagged

You are not signed in. Login or sign up in order to post.