Error in SQL Developer during creating tables - sql

I'm trying to create 3 tables using SQL Developer and have an error. Can't undersand why it happens.
Create table Album
(
"alb_code" integer primary key,
"alb_name" char(50),
"publ" char(50),
"publ_date" date not null
);
Create table Song
(
"song_code" integer primary key,
"song_name" char(50),
"auth" char(50),
"year" integer,
"style" char(30)
);
Create table Song_from_Album
(
"in_alb_code" integer primary key,
"time" float,
"no" integer,
FOREIGN KEY REFERENCES Song("song_code"),
FOREIGN KEY REFERENCES Album("alb_code")
);
I get an error:
Error starting at line : 1 in command -
Create table Album
(
"alb_code" integer primary key,
"alb_name" char(50),
"publ" char(50),
"publ_date" date not null
)
Error at Command Line : 1 Column : 14
Error report -
SQL Error: ORA-00955: имя уже задействовано для существующего объекта
00955. 00000 - "name is already used by an existing object"
*Cause:
*Action:
Error starting at line : 8 in command -
Create table Song
(
"song_code" integer primary key,
"song_name" char(50),
"auth" char(50),
"year" integer,
"style" char(30)
)
Error at Command Line : 8 Column : 14
Error report -
SQL Error: ORA-00955: имя уже задействовано для существующего объекта
00955. 00000 - "name is already used by an existing object"
*Cause:
*Action:
Error starting at line : 16 in command -
Create table Song_from_Album
(
"in_alb_code" integer primary key,
"time" float,
"no" integer,
FOREIGN KEY REFERENCES Song("song_code"),
FOREIGN KEY REFERENCES Album("alb_code")
)
Error at Command Line : 21 Column : 15
Error report -
SQL Error: ORA-00906: отсутствует левая скобка
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:

The first two tables are getting created, but third table has error.
Drop the tables and recreate with correction to third table syntax
The error "missing left parenthesis" is with the foreign key constraint declaration,
Use this instead
CONSTRAINT fk_no FOREIGN KEY ("no") REFERENCES Song("song_code"),
CONSTRAINT fk_alb_code FOREIGN KEY ("in_alb_code") REFERENCES Album("alb_code")
With this change, Song_Album table declaration will be like this
Create table Song_from_Album
(
"in_alb_code" integer primary key,
"time" float,
"no" integer,
CONSTRAINT fk_no FOREIGN KEY ("no") REFERENCES Song("song_code"),
CONSTRAINT fk_alb_code FOREIGN KEY ("in_alb_code") REFERENCES Album("alb_code")
);

Related

sql tables cant be imported for unknown reason

my tables don't want to be imported from vertabelo and I honestly don't know why. I'm using an oracle connection. if someone could give me a hand with it, it would be kind of you. I'll provide the code below with the errors it's giving. tables equipment, coach and rent are working. however, tables customer and training cant be imported and I honestly don't know what to do.
-- tables
-- Table: coach
CREATE TABLE coach (
id integer NOT NULL,
first_name varchar(255) NOT NULL,
second_name varchar(255) NOT NULL,
CONSTRAINT coach_pk PRIMARY KEY (id)
);
-- Table: customer
CREATE TABLE customer (
id int NOT NULL,
first_name Varchar(55) NOT NULL,
second_name Varchar(55) NOT NULL,
birth_date DateTime NULL,
skill_level int NOT NULL,
CONSTRAINT customer_pk PRIMARY KEY (id)
);
-- Table: equipment
CREATE TABLE equipment (
id int NOT NULL,
price int NOT NULL,
name_of_equipment int NOT NULL,
category_of_equipment int NOT NULL,
CONSTRAINT equipment_pk PRIMARY KEY (id)
);
-- Table: rent
CREATE TABLE rent (
equipment_id int NOT NULL,
customer_id int NOT NULL,
number_of_days date NOT NULL,
CONSTRAINT rent_pk PRIMARY KEY (number_of_days)
);
-- Table: training
CREATE TABLE training (
coach_id int NOT NULL,
customer_id int NOT NULL,
training_time_start time NOT NULL,
training_time_end time NOT NULL,
training_place_id int NOT NULL,
CONSTRAINT training_pk PRIMARY KEY (training_place_id)
);
-- foreign keys
-- Reference: rent_customer (table: rent)
ALTER TABLE rent ADD CONSTRAINT rent_customer FOREIGN KEY rent_customer (customer_id)
REFERENCES customer (id);
-- Reference: rent_equipment (table: rent)
ALTER TABLE rent ADD CONSTRAINT rent_equipment FOREIGN KEY rent_equipment (equipment_id)
REFERENCES equipment (id);
-- Reference: training_coach (table: training)
ALTER TABLE training ADD CONSTRAINT training_coach FOREIGN KEY training_coach (coach_id)
REFERENCES coach (id);
-- Reference: training_customer (table: training)
ALTER TABLE training ADD CONSTRAINT training_customer FOREIGN KEY training_customer (customer_id)
REFERENCES customer (id);
Error starting at line : 3 in command -
CREATE TABLE coach (
id integer NOT NULL,
first_name varchar(255) NOT NULL,
second_name varchar(255) NOT NULL,
CONSTRAINT coach_pk PRIMARY KEY (id)
)
Error report -
ORA-00955: name is already used by an existing object
00955. 00000 - "name is already used by an existing object"
*Cause:
*Action:
Error starting at line : 11 in command -
CREATE TABLE customer (
id int NOT NULL,
first_name Varchar(55) NOT NULL,
second_name Varchar(55) NOT NULL,
birth_date DateTime NULL,
skill_level int NOT NULL,
CONSTRAINT customer_pk PRIMARY KEY (id)
)
Error report -
ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
*Cause:
*Action:
Error starting at line : 21 in command -
CREATE TABLE equipment (
id int NOT NULL,
price int NOT NULL,
name_of_equipment int NOT NULL,
category_of_equipment int NOT NULL,
CONSTRAINT equipment_pk PRIMARY KEY (id)
)
Error report -
ORA-00955: name is already used by an existing object
00955. 00000 - "name is already used by an existing object"
*Cause:
*Action:
Error starting at line : 30 in command -
CREATE TABLE rent (
equipment_id int NOT NULL,
customer_id int NOT NULL,
number_of_days date NOT NULL,
CONSTRAINT rent_pk PRIMARY KEY (number_of_days)
)
Error report -
ORA-00955: name is already used by an existing object
00955. 00000 - "name is already used by an existing object"
*Cause:
*Action:
Error starting at line : 38 in command -
CREATE TABLE training (
coach_id int NOT NULL,
customer_id int NOT NULL,
training_time_start time NOT NULL,
training_time_end time NOT NULL,
training_place_id int NOT NULL,
CONSTRAINT training_pk PRIMARY KEY (training_place_id)
)
Error report -
ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
*Cause:
*Action:
Error starting at line : 49 in command -
ALTER TABLE rent ADD CONSTRAINT rent_customer FOREIGN KEY rent_customer (customer_id)
REFERENCES customer (id)
Error report -
ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:
Error starting at line : 53 in command -
ALTER TABLE rent ADD CONSTRAINT rent_equipment FOREIGN KEY rent_equipment (equipment_id)
REFERENCES equipment (id)
Error report -
ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:
Error starting at line : 57 in command -
ALTER TABLE training ADD CONSTRAINT training_coach FOREIGN KEY training_coach (coach_id)
REFERENCES coach (id)
Error report -
ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:
Error starting at line : 61 in command -
ALTER TABLE training ADD CONSTRAINT training_customer FOREIGN KEY training_customer (customer_id)
REFERENCES customer (id)
Error report -
ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:

ORA-00906:"missing left parenthesis" in sql developer

When I tried to create this table, this error appeared me and I don't know why
CREATE TABLE Empregado(
cod_empregado INTEGER,
cod_supervisor INTEGER,
cod_armazem INTEGER,
nome VARCHAR(40) NOT NULL,
morada VARCHAR(40) NOT NULL,
salario_semanal NUMERIC(*,2) NOT NULL,
formacao VARCHAR(40) NOT NULL,
CONSTRAINT pk_Empregado_cod_empregado PRIMARY KEY,
CONSTRAINT fk_Empregado_cod_supervisor FOREIGN KEY(cod_supervisor)
REFERENCES Empregado(cod_supervisor),
CONSTRAINT fk_Empregado_cod_armazem FOREIGN KEY(cod_armazem) REFERENCES
Armazem(cod_armazem)
);
And this is the output
Error report -
ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:
The issue that throws out the error you are seeing is caused by the PRIMARY KEY constraint: you didn't state WHICH column is the primary key. The PK column must be in parentheses; the opening parenthesis is missing (along with the rest), and that is the first syntax violation Oracle sees.
After you fix that, you will get another error, on the first foreign key, because you are referencing the wrong table (or if it should reference the same table you are creating, you are referencing the wrong COLUMN).

(Oracle) Adding a constraint after a table has been made

I'm relatively new to Databases and Oracle and I'm atempting to make a database for a project involving 2 tables; Klant(customer) and Account_. These 2 both have each others PK as a foreign key. Since this is the case I had to make the foreign keys after the creation of the tables, resulting in this
DROP TABLE KLANT CASCADE CONSTRAINTS;
DROP TABLE ACCOUNT_ CASCADE CONSTRAINTS;
CREATE TABLE KLANT
(
"KlandId" INT PRIMARY KEY,
"AccountId" INT,
"Voornaam" VARCHAR2(64)NOT NULL,
"Achternaam" VARCHAR2(64) NOT NULL,
"GENDER" CHAR(1) DEFAULT 'M' CHECK (UPPER(GENDER) in ('M','F')),
"Tussenvoegsels" VARCHAR2(16),
"EmailAdres" VARCHAR2(64),
"Land" VARCHAR2(64) DEFAULT 'Nederland',
"Stad" VARCHAR2(64),
"Adres" VARCHAR2(64),
"Toevoeging" CHAR(1));
CREATE TABLE Account_
(
"AccountId" INT PRIMARY KEY,
"KlantId_" INT,
"GebruikersNaam" VARCHAR2(64)UNIQUE NOT NULL,
"Wachtwoord" VARCHAR2(64)
);
ALTER TABLE KLANT
ADD CONSTRAINT fk_accountId FOREIGN KEY (AccountId) REFERENCES "Account_"(AccountId);
ALTER TABLE Account_
ADD CONSTRAINT fk_klantId FOREIGN KEY (KlantId_) REFERENCES "Klant"(KlantId);
This yielded me the following error:
Error starting at line : 39 in command -
ALTER TABLE KLANT
ADD CONSTRAINT fk_accountId FOREIGN KEY (AccountId) REFERENCES "Account_"(AccountId)
Error report -
SQL Error: ORA-00904: "ACCOUNTID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Sorry for all the dutch words :(
My question being: Where did I mess up, because it probably is something riduculously stupid.
ALTER TABLE KLANT
ADD CONSTRAINT fk_accountId FOREIGN KEY ("AccountId") REFERENCES Account_("AccountId");
Name of the Account_ Table should not be in double quotes. Same for the other table .
Quote AccountId. In Oracle objects are generally uppercase. When you use AccountId without quoting it, Oracle will look for ACCOUNTID.

Multiple errors dropping and creating tables

I'm not good at writing create scripts. And the SQL Developer error messages don't help me. I'm looking for someone to help me figure out what's wrong because I can't do this alone.
Here is my code:
/*Drops */
DROP TABLE Accountsite CASCADE CONSTRAINTS;
DROP TABLE Player CASCADE CONSTRAINTS;
DROP TABLE Stream CASCADE CONSTRAINTS;
DROP TABLE Server CASCADE CONSTRAINTS;
DROP TABLE Activegame CASCADE CONSTRAINTS;
DROP TABLE Livegame CASCADE CONSTRAINTS;
DROP TABLE Toplist CASCADE CONSTRAINTS;
DROP TABLE Champion CASCADE CONSTRAINTS;
DROP TABLE Skin CASCADE CONSTRAINTS;
DROP TABLE Sale CASCADE CONSTRAINTS;
DROP TABLE PlayerServer CASCADE CONSTRAINTS;
DROP TABLE ActiveServer CASCADE CONSTRAINTS;
/*Creates */
CREATE TABLE Accountsite(
AccountID NUMBER PRIMARY KEY NOT NULL,
PasswordAcc VARCHAR(20) NULL,
Email VARCHAR(20) NULL,
Playername VARCHAR(20) NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername));
CREATE TABLE Player(
PlayerID NUMBER PRIMARY KEY,
Mostplayed VARCHAR(20) NOT NULL,
RankID NUMBER(10) NOT NULL,
Playername VARCHAR(20) NOT NULL);
CREATE TABLE Stream(
StreamID NUMBER PRIMARY KEY,
StreamAdress VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername));
CREATE TABLE Server(
ServerID NUMBER PRIMARY KEY,
Servername VARCHAR(20));
CREATE TABLE Activegame(
GameID NUMBER PRIMARY KEY);
CREATE TABLE Livegame(
SpectateID NUMBER PRIMARY KEY);
CREATE TABLE Toplist(
ToplistID NUMBER PRIMARY KEY,
ToplistFunction VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
Championname VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(Champion) REFERENCES Champion (Champion));
CREATE TABLE Champion(
ChampionID NUMBER PRIMARY KEY,
Championname VARCHAR(20) NOT NULL,
Championskill1 VARCHAR(20) NOT NULL,
Championskill2 VARCHAR(20) NOT NULL,
Championskill3 VARCHAR(20) NOT NULL,
Championskill4 VARCHAR(20) NOT NULL,
Championcost NUMBER(10) DEFAULT(6300),
SkinID NUMBER(10) NOT NULL,
SaleID NUMBER(10) NOT NULL,
FOREIGN KEY(SkinID) REFERENCES Skin (SkinID),
FOREIGN KEY(SaleID) REFERENCES Sale (SaleID));
CREATE TABLE Skin(
SkinID NUMBER PRIMARY KEY,
Skinname VARCHAR(20) NOT NULL,
Skincost NUMBER(10) NOT NULL);
CREATE TABLE Sale(
SaleID NUMBER PRIMARY KEY);
CREATE TABLE PlayerServer(
Playername VARCHAR(20) NOT NULL,
ServerIDPlayer NUMBER NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(ServerIDPlayer) REFERENCES Server (ServerID),
Constraint PlayerserverID PRIMARY KEY (Playername, ServerIDPlayer));
CREATE TABLE ActiveServer(
GameIDServer NUMBER NOT NULL,
ServerIDGame NUMBER NOT NULL,
FOREIGN KEY(GameIDServer) REFERENCES Acrivegame (GameID),
FOREIGN KEY(ServerIDGame) REFERENCES Server (ServerID),
Constraint ActiveserverID PRIMARY KEY (GameIDServer, ServerIDGame));
commit;
And the errors are as follows:
Error starting at line : 2 in command -
DROP TABLE Accountsite CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table PLAYER dropped.
Error starting at line : 4 in command -
DROP TABLE Stream CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table SERVER dropped.
Table ACTIVEGAME dropped.
Table LIVEGAME dropped.
Error starting at line : 8 in command -
DROP TABLE Toplist CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 9 in command -
DROP TABLE Champion CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table SKIN dropped.
Table SALE dropped.
Error starting at line : 12 in command -
DROP TABLE PlayerServer CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 13 in command -
DROP TABLE ActiveServer CASCADE CONSTRAINTS
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 16 in command -
CREATE TABLE Accountsite(
AccountID NUMBER PRIMARY KEY NOT NULL,
PasswordAcc VARCHAR(20) NULL,
Email VARCHAR(20) NULL,
Playername VARCHAR(20) NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername))
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table PLAYER created.
Error starting at line : 29 in command -
CREATE TABLE Stream(
StreamID NUMBER PRIMARY KEY,
StreamAdress VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername))
Error report -
SQL Error: ORA-02270: Geen overeenkomende unieke of primaire sleutel voor deze kolomlijst.
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view
Table SERVER created.
Table ACTIVEGAME created.
Table LIVEGAME created.
Error starting at line : 45 in command -
CREATE TABLE Toplist(
ToplistID NUMBER PRIMARY KEY,
ToplistFunction VARCHAR(20) NOT NULL,
Playername VARCHAR(20) NOT NULL,
Championname VARCHAR(20) NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(Champion) REFERENCES Champion (Champion))
Error report -
SQL Error: ORA-00904: "CHAMPION": ongeldige ID
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error starting at line : 53 in command -
CREATE TABLE Champion(
ChampionID NUMBER PRIMARY KEY,
Championname VARCHAR(20) NOT NULL,
Championskill1 VARCHAR(20) NOT NULL,
Championskill2 VARCHAR(20) NOT NULL,
Championskill3 VARCHAR(20) NOT NULL,
Championskill4 VARCHAR(20) NOT NULL,
Championcost NUMBER(10) DEFAULT(6300),
SkinID NUMBER(10) NOT NULL,
SaleID NUMBER(10) NOT NULL,
FOREIGN KEY(SkinID) REFERENCES Skin (SkinID),
FOREIGN KEY(SaleID) REFERENCES Sale (SaleID))
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Table SKIN created.
Table SALE created.
Error starting at line : 74 in command -
CREATE TABLE PlayerServer(
Playername VARCHAR(20) NOT NULL,
ServerIDPlayer NUMBER NOT NULL,
FOREIGN KEY(Playername) REFERENCES Player (Playername),
FOREIGN KEY(ServerIDPlayer) REFERENCES Server (ServerID),
Constraint PlayerserverID PRIMARY KEY (Playername, ServerIDPlayer))
Error report -
SQL Error: ORA-02270: Geen overeenkomende unieke of primaire sleutel voor deze kolomlijst.
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view
Error starting at line : 81 in command -
CREATE TABLE ActiveServer(
GameIDServer NUMBER NOT NULL,
ServerIDGame NUMBER NOT NULL,
FOREIGN KEY(GameIDServer) REFERENCES Acrivegame (GameID),
FOREIGN KEY(ServerIDGame) REFERENCES Server (ServerID),
Constraint ActiveserverID PRIMARY KEY (GameIDServer, ServerIDGame))
Error report -
SQL Error: ORA-00942: Tabel of view bestaat niet.
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Commit complete.
What am I doing wrong?
There are several issues with your script. Basically when you include foreign key constraints, they have to be pointing to a unique column which is in a table that already exists (has to be created before the referencing table).
Errors on trying to drop a table
You basically get an ORA-00942 because your table does not exist, thus it cannot be dropped. As a workaround you could catch that exception. It has been described in this answer.
Errors on trying to create a table
You have several issues in this topic. First one is when you execute the create statement of table Accountsite. You also get an ORA-00942 here, because table Player which you are trying to reference in foreign key constraint does not exist. You need to create it before Accountsite, so that it can reference something that exists.
Next error occurs while creating a table Stream. It's the ORA-02270. You cannot reference a column from another table which is not unique. You need to make Playername column unique in table Player. Note that when you fix the first error with Accountsite table, you would have the same error for this table as for Stream, since you are trying to reference a column which is not unique in both create table statements (so you also need to fix the second error and it will go without errors).
Now the Toplist table. There is no Champion column in your Champion table. You probably mean Championname. In this case also Champion table needs to be created before the Toplist table, since you cannot create a foreign key constraint to a non-existing table. You also need to declare your Championname column in Champion table unique (the very same like you do with Playername in table Player).
In Champion you reference a Sale and Skin table - they both need to be created before Champion table (see explanation above).
As for PlayerServer the error will solve itself when you create a unique constraint on Player(Playername).
In ActiveServer you have a typo in referencing "Acrivegame" which I believe should be Activegame.

Invalid datatype when adding constraint in Oracle

I want to create this table in Oracle. This is only the table SQL script.
-- CREATE TABLES SECTION -------------------------------------------------
-- TABLE DATACENTER
CREATE TABLE DATACENTER(
DATACENTERID INTEGER NOT NULL,
NAME VARCHAR2(80 ) NOT NULL,
LOCATION VARCHAR2(200 ),
DCALLOWEDWEIGHTKG NUMBER(9,0),
DCMAXIMUMWEIGHTKG NUMBER(9,0),
DCALLOWEDPOWERWATT NUMBER(9,0),
DCMAXPOWERWATT NUMBER(9,0),
DCALLOWCOOLINGPOWERBTU NUMBER(9,0),
DCMAXCOOLINGPOWERBTU NUMBER(9,0),
DESCRIPTION CLOB
)
/
-- ADD KEYS FOR TABLE DATACENTER
ALTER TABLE DATACENTER ADD CONSTRAINT DATACENTERID PRIMARY KEY (DATACENTERID)
/
-- TABLE COMPONENT
CREATE TABLE COMPONENT(
COMPONENTID INTEGER NOT NULL,
DATACENTERID INTEGER,
FKCOMPONENTID INTEGER,
COMPONENTSTATSID INTEGER NOT NULL
)
/
-- ADD KEYS FOR TABLE COMPONENT
ALTER TABLE COMPONENT ADD CONSTRAINT COMPONENTID PRIMARY KEY (COMPONENTID)
/
-- CREATE RELATIONSHIPS SECTION -------------------------------------------------
ALTER TABLE COMPONENT ADD CONSTRAINT IS PART OF A FOREIGN KEY (DATACENTERID) REFERENCES DATACENTER (DATACENTERID)
/
ALTER TABLE COMPONENT ADD CONSTRAINT IS A SUBPART OF FOREIGN KEY (FKCOMPONENTID) REFERENCES COMPONENT (COMPONENTID)
/
The error stack:
table DATACENTER created.
table DATACENTER altered.
table COMPONENT created.
table COMPONENT altered.
Error starting at line 39 in command:
ALTER TABLE COMPONENT ADD CONSTRAINT IS PART OF A FOREIGN KEY (DATACENTERID) REFERENCES DATACENTER (DATACENTERID)
Error report:
SQL Error: ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
*Cause:
*Action:
Error starting at line 42 in command:
ALTER TABLE COMPONENT ADD CONSTRAINT IS A SUBPART OF FOREIGN KEY (FKCOMPONENTID) REFERENCES COMPONENT (COMPONENTID)
Error report:
SQL Error: ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
*Cause:
*Action:
EDIT I edited the code because I saw that some SQL statements are missing.
I can provide the schema if you want?
Best wishes
Your constraint name IS PART OF A is an illegal identifier (because of the spaces).
You need to remove the spaces, e.g. IS_PART_OF_A:
ALTER TABLE COMPONENT
ADD CONSTRAINT IS_PART_OF_A
FOREIGN KEY (DATACENTERID)
REFERENCES DATACENTER (DATACENTERID)
Edit
I also realized that your script is not correctly terminating the individual statements. There is a ; (or /) missing after the first CREATE TABLE. And the first ALTER TABLE is not properly terminated as well. I don't know if that is a copy & paste error though.
Edit2:
Here is the complete script with correct names, statement termination and in the correct order:
CREATE TABLE COMPONENT(
COMPONENTID INTEGER NOT NULL,
DATACENTERID INTEGER,
FKCOMPONENTID INTEGER,
COMPONENTSTATSID INTEGER NOT NULL
)
/
CREATE TABLE DATACENTER(
DATACENTERID INTEGER NOT NULL,
NAME VARCHAR2(80 ) NOT NULL,
LOCATION VARCHAR2(200 ),
DCALLOWEDWEIGHTKG NUMBER(9,0),
DCMAXIMUMWEIGHTKG NUMBER(9,0),
DCALLOWEDPOWERWATT NUMBER(9,0),
DCMAXPOWERWATT NUMBER(9,0),
DCALLOWCOOLINGPOWERBTU NUMBER(9,0),
DCMAXCOOLINGPOWERBTU NUMBER(9,0),
DESCRIPTION CLOB
)
/
ALTER TABLE DATACENTER ADD CONSTRAINT DATACENTERID PRIMARY KEY (DATACENTERID)
/
ALTER TABLE COMPONENT ADD CONSTRAINT COMPONENTID PRIMARY KEY (COMPONENTID)
/
ALTER TABLE COMPONENT ADD CONSTRAINT IS_PART_OF_A FOREIGN KEY (DATACENTERID) REFERENCES DATACENTER (DATACENTERID)
/