sql tables cant be imported for unknown reason - sql

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:

Related

Error report - ORA-00904: : invalid identifier 00904. 00000 - "%s: invalid identifier"

This is my SQL Oracle script and I cannot figure out why I keep getting the following error when I try and run this code:
I keep getting this exact code on each table I try to run. Can anyone point me in the right direction as to why my code will not run? I have tried researching this myself ALL DAY LONG and cant get it.**
Error starting at line : 12 in command -
CREATE TABLE COURSE (
CRS_CODE VARCHAR (8) NOT NULL,
CRS_DESCRIPTION VARCHAR (35) NOT NULL,
CONSTRAINT CRS_CREDIT NOT NULL,
CHECK (CRS_CREDIT IN (1,2,3,4)),
PRIMARY KEY (CRS_CODE))
Error report -
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
SQL>
**CODE BEFORE ERROR:**
/* This script file creates the following tables:*/
/*COURSE, CLASS, ENROLL, STUDENT */
set echo on;
set serveroutput on ;
/*DROP TABLE COURSE;
DROP TABLE CLASS;
DROP TABLE STUDENT;
DROP TABLE ENROLL;*/
CREATE TABLE COURSE (
CRS_CODE VARCHAR (8) NOT NULL,
CRS_DESCRIPTION VARCHAR (35) NOT NULL,
CONSTRAINT CRS_CREDIT NOT NULL,
CHECK (CRS_CREDIT IN (1,2,3,4)),
PRIMARY KEY (CRS_CODE));
CREATE TABLE CLASS (
CLASS_CODE NUMBER (5) NOT NULL,
CONSTRAINT CLASS_SECTION_Ck NOT NULL,
CLASS_TIME VARCHAR (25) NOT NULL,
CLASS_ROOM CHAR (6),
CHECK (CLASS_SECTION IN (1,2,3,4,5,6,7,8)),
PRIMARY KEY (CLASS_CODE),
FOREIGN KEY (CRS_CODE) REFERENCES COURSE (CRS_CODE));
CREATE TABLE STUDENT (
STU_NUM INTEGER NOT NULL,
STU_LNAME VARCHAR (25) NOT NULL,
STU_FNAME VARCHAR (20) NOT NULL,
STU_INIT CHAR (1),
STU_DOB DATE NOT NULL,
CONSTRAINTS STU_HRS_Ck DEFAULT 0 NOT NULL,
STU_CLASS CHARACTER(2) REFERENCES "Fr", "So", "Jr", "Gr" NOT NULL,
CONSTRAINT STU_GPA_Ck DEFAULT 0.00 NOT NULL,
STU_PHONE VARCHAR (4) NOT NULL,
PRIMARY KEY (STU_NUM),
CHECK (STU_HRS <= 0),
CHECK (STU_HRS >= 1000),
CHECK (STU_GPA BETWEEN 0.00 AND 4.00));
CREATE TABLE ENROLL (
ENROLL_GRADE_Ck VARCHAR (1) REFERENCES "A","B","C","D","F","I","W", "Z", DEFAULT Z NOT NULL,
FOREIGN KEY (STU_NUM) REFERENCES STUDENT (STU_NUM),
FOREIGN KEY (CLASS_CODE) REFERENCES CLASS (CLASS_CODE),
PRIMARY KEY (CLASS_CODE));
commit;
It is not clear from your question whether you are trying to create a COLUMN level CONSTRAINT or not. If you are trying to create a COLUMN level CONSTRAINT, then there seems to be a syntax error in your CONSTRAINT definition (a comma before the word CONSTRAINT).
See the following link from Oracle:
https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj13590.html
It has examples on how to define constraints including COLUMN level constraints. You may want to compare your CONSTRAINT clause with the examples to see if there are errors in your CONSTRAINTS.

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 table name without using a reserved word?

I'm creating a table using Oracle SQL, and when trying to create a table called 'Card' I keep getting the error that it's an invalid table name. Here's my code:
CREATE TABLE Card
(
CardNumber varchar2(20) Not Null,
CardType varchar2(5) Not Null,
CONSTRAINT CustomerIDForeignKey FOREIGN KEY (CustomerID) REFERENCES (Customer),
CONSTRAINT CardTypeConstraint CHECK (CardType='Credit' or CardType='Debit' or CardType='Gift')
)
And here's the error code I'm getting:
Error starting at line : 1 in command -
CREATE TABLE Card
(
CardNumber varchar2(20) Not Null,
CardType varchar2(5) Not Null,
CONSTRAINT CustomerIDForeignKey FOREIGN KEY (CustomerID) REFERENCES (Customer),
CONSTRAINT CardTypeConstraint CHECK (CardType='Credit' or CardType='Debit' or CardType='Gift')
)
Error report -
SQL Error: ORA-00903: invalid table name
00903. 00000 - "invalid table name"
*Cause:
*Action:
Any help would be appreciated! I didn't find 'Card' on the list of Oracle SQL's reserved words, so I'm not sure what the issue is. Thank you!
You need to add column CustomerId to Card table and change refrences to table_name(column_name):
SqlFiddleDEMO
CREATE TABLE Customer(CustomerID INT PRIMARY KEY);
CREATE TABLE Card(
CardNumber varchar2(20) Not Null,
CardType varchar2(5) Not Null,
CustomerId INT NOT NULL,
CONSTRAINT CustomerIDForeignKey FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerId),
CONSTRAINT CardTypeConstraint CHECK (CardType IN ('Credit', 'Debit' ,'Gift'))
);
Also you can replace:
CHECK (CardType='Credit' or CardType='Debit' or CardType='Gift')
with:
CHECK (CardType IN ('Credit', 'Debit' ,'Gift'))
You can think about:
Adding Primary Key to Card table
Hashing/encrypting card number (do not store as plain text)
Creating CreditCardType dictionary table

Can't create table in Oracle Developer

Hi I am very new to SQL and having a problem for creating the table.
I have been looking at this code for the past two days now and I can not seem to get it to work. It keeps giving me "ORA-00907: missing right parenthesis" I know that this is a topic that comes up a lot but for some reason none of the examples I have seen has helped me. Can someone please tell me why I got this error and how do I fix it. I am pretty sure that it has nothing to do with my parenthesis, maybe its my CONTRAINTS
Here is my Code
create TABLE Employee
(
EmployeeID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Phone INT(10) NOT NULL,
JobTitle VARCHAR(10) NOT NULL
);
create TABLE Airplane
(
AirplaneID VARCHAR(10) PRIMARY KEY,
Capacity INT(1000) NOT NULL,
Modle VARCHAR(10) NOT NULL
);
create TABLE Route
(
FlightID VARCHAR(10) PRIMARY KEY,
Origin VARCHAR(20) NOT NULL,
Destination VARCHAR(20) NOT NULL,
ETD INT(10) NOT NULL,
ETA INT(10) NOT NULL
);
create TABLE Customer
(
CustomerID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(10) NOT NULL,
PhoneNumber INT(30) NOT NULL
);
create TABLE Maintenance
(
MaintenanceID VARCHAR(20) PRIMARY KEY,
MaintenanceDate date NOT NULL,
AirplaneID VARCHAR(10) NOT NULL,
EmployeeID VARCHAR(10) NOT NULL,
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
);
create TABLE Flight
(
FlightID VARCHAR(10),
FlightDate date,
AirplaneID VARCHAR(10),
ATD INT(10) NOT NULL,
ATA INT(10) NOT NULL,
FOREIGN KEY (FlightID) REFERENCES Flight(FlightID),
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
CONSTRAINT PK_FlightID PRIMARY KEY (FlightID,FlightDate)
);
create TABLE Reservation
(
ReservationID VARCHAR(20) PRIMARY KEY,
CustomerID VARCHAR(10) NOT NULL,
FlightID VARCHAR(10) NOT NULL,
FlightDate date NOT NULL,
Fare float,
PaymentMethod VARCHAR(20),
CardNumber INT(30) NOT NULL,
ExperationDate date,
check (PaymentMethod = "Cash" OR PaymentMethod ="Credit" OR PaymentMethod
="Cheque",
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID),
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
);
create TABLE CrewResveration
(
EmployeeID VARCHAR(10),
FlightID VARCHAR(10),
FlightDate date NOT NULL,
Role VARCHAR(20) NOT NULL,
ShiftHour INT(10) NOT NULL,
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
FORIGNKEY (EmployeeID) REFERENCES Employee(EmployeeID)
CONSTRAINT PK_CrewAssignment PRIMARY (FlightID,FlightDate,EmployeeID)
);
Here are the results I get when I run the code:
Error starting at line : 1 in command -
create TABLE Employee
(
EmployeeID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Phone INT(20) NOT NULL,
JobTitle VARCHAR(10) NOT NULL
)
Error at Command Line : 5 Column : 10
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 10 in command -
create TABLE Airplane
(
AirplaneID VARCHAR(10) PRIMARY KEY,
Capacity INT(1000) NOT NULL,
Modle VARCHAR(10) NOT NULL
)
Error at Command Line : 13 Column : 13
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 18 in command -
create TABLE Route
(
FlightID VARCHAR(10) PRIMARY KEY,
Origin VARCHAR(20) NOT NULL,
Destination VARCHAR(20) NOT NULL,
ETD INT(10) NOT NULL,
ETA INT(10) NOT NULL
)
Error at Command Line : 23 Column : 8
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 28 in command -
create TABLE Customer
(
CustomerID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(10) NOT NULL,
PhoneNumber INT(30) NOT NULL
)
Error at Command Line : 32 Column : 16
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 36 in command -
create TABLE Maintenance
(
MaintenanceID VARCHAR(20) PRIMARY KEY,
MaintenanceDate date NOT NULL,
AirplaneID VARCHAR(10) NOT NULL,
EmployeeID VARCHAR(10) NOT NULL,
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
)
Error at Command Line : 42 Column : 37
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 46 in command -
create TABLE Flight
(
FlightID VARCHAR(10),
FlightDate date,
AirplaneID VARCHAR(10),
ATD INT(10) NOT NULL,
ATA INT(10) NOT NULL,
FOREIGN KEY (FlightID) REFERENCES Flight(FlightID),
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
CONSTRAINT PK_FlightID PRIMARY KEY (FlightID,FlightDate)
)
Error at Command Line : 51 Column : 8
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 60 in command -
create TABLE Reservation
(
ReservationID VARCHAR(20) PRIMARY KEY,
CustomerID VARCHAR(10) NOT NULL,
FlightID VARCHAR(10) NOT NULL,
FlightDate date NOT NULL,
Fare float,
PaymentMethod VARCHAR(20),
CardNumber INT(30) NOT NULL,
ExperationDate date,
check (PaymentMethod = "Cash" OR PaymentMethod ="Credit" OR PaymentMethod
="Cheque",
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID),
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
)
Error at Command Line : 68 Column : 15
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 76 in command -
create TABLE CrewResveration
(
EmployeeID VARCHAR(10),
FlightID VARCHAR(10),
FlightDate date NOT NULL,
Role VARCHAR(20) NOT NULL,
ShiftHour INT(10) NOT NULL,
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
FORIGNKEY (EmployeeID) REFERENCES Employee(EmployeeID)
CONSTRAINT PK_CrewAssignment PRIMARY (FlightID,FlightDate,EmployeeID)
)
Error at Command Line : 82 Column : 14
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
The error description is misleading, but the pointer (line 5, column 10) points to exactly after reading the word "INT" ... which, is unknown by him. He should state he doesn't understand that, but he mentions something with parenthesis, which ironically are actually correct. Unfortunately, it happens on occasions that error messages are misleading, and you have to think one step further.
The problem is with your data types. INT is not a valid Oracle datatype. Try this instead:
create TABLE Employee ( EmployeeID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Phone NUMBER(10) NOT NULL,
JobTitle VARCHAR(10) NOT NULL );

Error in SQL Developer during creating tables

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")
);