Name already existing error in SQL Developer - oracle

I got some help last night on this code but now I am getting a different error. My professor is STILL not answering me so I am coming to you guys. Here is the code:
--Create Volunteer Supervisor
CREATE TABLE Volunteer_Supervisor
(
PH_Person_ID Number(10) NOT NULL,
EM_Person_ID Number(10) NOT NULL,
VO_Person_ID Number(10) NOT NULL,
End_Date Date NOT NULL,
Begin_Date Date NOT NULL,
Hours_Worked Number(4) NULL,
PWork_Unit_ID Number(4) NULL,
PRIMARY KEY (PWork_Unit_ID),
CONSTRAINT CCPHPersonID_FK FOREIGN KEY (PH_Person_ID) References Physician (PH_Person_ID),
CONSTRAINT CCEMPersonID_FK FOREIGN KEY (EM_Person_ID) References Employee (EM_Person_ID),
CONSTRAINT CCVOPersonID_FK FOREIGN KEY (VO_Person_ID) References Volunteer (VO_Person_ID),
CONSTRAINT CCPWorkUnitID_PK FOREIGN KEY (PWork_Unit_ID) References Work_Unit (PWork_Unit_ID)
);
Now I have changed the names but still getting this error:
Error report -
ORA-00955: name is already used by an existing object
00000 - "name is already used by an existing object"
*Cause:
*Action:
What am I missing?

If you are sure that no such table Volunteer_Supervisor exists, You may try below code -
CREATE TABLE Volunteer_Supervisor
(
PH_Person_ID Number(10) NOT NULL,
EM_Person_ID Number(10) NOT NULL,
VO_Person_ID Number(10) NOT NULL,
End_Date Date NOT NULL,
Begin_Date Date NOT NULL,
Hours_Worked Number(4) NULL,
PWork_Unit_ID Number(4) NULL,
PRIMARY KEY (PWork_Unit_ID),
FOREIGN KEY (PH_Person_ID) References Physician (PH_Person_ID),
FOREIGN KEY (EM_Person_ID) References Employee (EM_Person_ID),
FOREIGN KEY (VO_Person_ID) References Volunteer (VO_Person_ID),
FOREIGN KEY (PWork_Unit_ID) References Work_Unit (PWork_Unit_ID)
);

Related

I get this error executing table three "The specified constraint name has to be unique. *Action: Specify a unique constraint name for the constraint

Table One:
CREATE TABLE Customer
(CustNo VARCHAR2(8) CONSTRAINT CustNoNotNull NOT NULL,
CustName VARCHAR2(30) CONSTRAINT CustNameNotNull NOT NULL,
Address VARCHAR2(50) CONSTRAINT AddressNotNull NOT NULL,
Internal CHAR(1) CONSTRAINT InternalNotNull NOT NULL,
Contact VARCHAR2(35) CONSTRAINT ContractNotNull NOT NULL,
Phone VARCHAR2(11) CONSTRAINT CPhoneNotNull NOT NULL,
City VARCHAR2(30) CONSTRAINT CityNotNull NOT NULL,
State VARCHAR2(2) CONSTRAINT StateNotNull NOT NULL,
Zip VARCHAR2(10) CONSTRAINT zipNotNull NOT NULL,
CONSTRAINT PK_CUSTOMER PRIMARY KEY (CustNo) ) ;
Table Two:
CREATE TABLE Facility
(FacNo VARCHAR2(8) CONSTRAINT FacNoNotNull NOT NULL,
FacName VARCHAR2(30) CONSTRAINT FacNameNotNull NOT NULL,
CONSTRAINT PK_FACILITY PRIMARY KEY (FacNo)
CONSTRAINT Unique_FacName UNIQUE(FacName) );
Table Three:
CREATE TABLE EVENTREQUEST
( EVENTNO VARCHAR2(8) CONSTRAINT EVENTNONOTNULL NOT NULL,
DATEHELD DATE CONSTRAINT DATEHELDNOTNULL NOT NULL,
DATEREQ DATE CONSTRAINT DATEREQNOTNULL NOT NULL,
CUSTNO VARCHAR2(8) CONSTRAINT CUSTNONOTNULL NOT NULL ,
FACNO VARCHAR2(8) CONSTRAINT FACNONOTNULL NOT NULL,
DATEAUTH DATE CONSTRAINT DATEAUTHNULL NULL,
STATUS VARCHAR2(10) CONSTRAINT STATUSNOTNULL NOT NULL,
ESTCOST VARCHAR2(25) CONSTRAINT ESTCOSTNOTNULL NOT NULL,
ESTAUDIENCE VARCHAR2(10) CONSTRAINT ESTAUDIENCENOTNULL NOT NULL,
BUDNO VARCHAR2(8) CONSTRAINT BUDNONULL NULL,
CONSTRAINT PK_EVENTREQUEST PRIMARY KEY (EVENTNO),
CONSTRAINT FK_CUSTNO FOREIGN KEY (CUSTNO) REFERENCES CUSTOMER (CUSTNO),
CONSTRAINT FK_FACNO FOREIGN KEY (FACNO) REFERENCES FACILITY (FACNO),
CONSTRAINT CHECK_EVENTREQUEST_STATUS CHECK(STATUS IN('PENDING','DENIED','APPROVED')));
I get this error executing Table Three:
"The specified constraint name has to be unique. *Action: Specify a unique constraint name for the constraint
How can I prevent this error from occurring?
In Oracle, constraints are a type of object, and they have an identifier (a name by which they are distinguished from other objects). All constraints, on all tables within a schema, share the same name space. Which means you can't have two constraints with the same name in the same schema, even if they are on different tables.
Moreover, identifiers by default are case insensitive. On the second table you defined a constraint FacNoNotNull, and on the third table you are trying to define a constraint FACNONOTNULL. Since identifiers are case insensitive, this is the same name - so you get an exception.
A completely wrong approach (which would work, unfortunately - so many people may be inclined to do it even though it's wrong) is to enclose names in double-quotes, which makes them case sensitive. Don't do that!
Rather, one has to ask - why do you need to name your NOT NULL constraints in the first place? Just add the key words NOT NULL after the column definition; it is very hard to see when or where you would need to know the name of each such constraint.

No matching unique or primary key for column-list in oracle

CREATE TABLE student_detailS01
(USN VARCHAR(20) NOT NULL,
STUDENT_NAME VARCHAR2(20) NOT NULL,
BRANCH VARCHAR2(20) NOT NULL,
CONTACT_NO NUMBER(10) NOT NULL,
FATHERS_NAME VARCHAR2(20) NOT NULL,
HOME_ADDRESS VARCHAR(50) NOT NULL,
DOB DATE NOT NULL,
LOCAL_ADDRESS VARCHAR2(50),
EMAIL_ID VARCHAR2(20),
DOJ DATE,
HID NUMBER NOT NULL,
PRIMARY KEY (USN,HID)
);
CREATE TABLE MESS(
S_NO NUMBER NOT NULL,
HID NUMBER REFERENCES STUDENT_DETAILS01(HID),
NO_OF_BREAKFAST INT,
NO_OF_MEALS INT,
AMT_OF_BREAKFAST INT,
AMT_OF_MEALS INT,
TOTAL INT NOT NULL,
PRIMARY KEY(S_NO)
);
student_details01 table is executed, but mess table gives the following error:
no matching unique or primary key for this column-list.
The ORA-2270 : no matching unique or primary key for this column-list error is quite simple: it happens when the columns we reference in the foreign key do not match a primary key or unique constraint on the parent table. Common reasons for this are
the parent lacks a constraint altogether
the parent table's constraint is a compound key and we haven't
referenced all the columns in the foreign key statement.
To fix your issue try as below:
CREATE TABLE MESS
(
S_NO NUMBER,
S_HID NUMBER,
S_UNO VARCHAR (20), --Added Column
NO_OF_BREAKFAST INT,
NO_OF_MEALS INT,
AMT_OF_BREAKFAST INT,
AMT_OF_MEALS INT,
TOTAL INT NOT NULL,
CONSTRAINT MESS_pk PRIMARY KEY (S_NO),
CONSTRAINT fk_id_dtls FOREIGN KEY
(S_HID, S_UNO)
REFERENCES student_detailS01 (HID, USN)
);

data base oracle foreign key error ORA-02270: no matching unique or primary key for this column-list

while making foreign key in player table it shows following error
ORA-02270: no matching unique or primary key for this column-list
create table person
(
per_ssn number(10) not null,
per_name varchar2(30) not null,
CONSTRAINT pk_PersonID PRIMARY KEY (per_ssn,per_name)
);
create table Player
(
player_ssn number(10) not null,
player_name varchar2(30) not null,
football_club_name varchar2(30) not null,
p_age number(2) not null,
p_weight number(3) not null,
p_height number(10) not null,
country varchar2(20) not null,
p_starting_date date not null,
p_ending_date date not null
);
alter table Player
add constraint player_ssn
FOREIGN KEY (player_ssn)
REFERENCING person (per_ssn)on delete cascade
I want to make two primary keys in person table and then want to refer these
primary keys in player table.
If I make one primary key and then refer it in player table, then it does not show error but I want to make two primary keys.
You should be referencing per_ssn,per_name because that is your PK on person.
Anyway, think about making per_ssn your PK in person table
alter table Player
add constraint player_ssn
FOREIGN KEY (player_ssn,player_name)
REFERENCING person (per_ssn,per_name)on delete cascade

ORA-01747_invalid user.table.column, table.column, or column specification

I don't have so many experience in this..I've got this error when I tried to insert into table.
Here's code:
CREATE TABLE factory
(idfactory INT NOT NULL,
location_id INT NOT NULL,
owner INT NOT NULL,
CONSTRAINT factory_id_pk PRIMARY KEY(idfactory),
CONSTRAINT f_location_id_fk FOREIGN KEY(location_id) REFERENCES location(idLocation),
CONSTRAINT s_owner_id_fk FOREIGN KEY(owner) REFERENCES employees(idEmployee));
CREATE TABLE location
(idLocation INT NOT NULL,
Name VARCHAR(45),
region_id INT NOT NULL,
CONSTRAINT location_id_pk PRIMARY KEY(idLocation),
CONSTRAINT p_location_id_fk FOREIGN KEY(region_id) REFERENCES region(idRegion));
CREATE TABLE employees
(idEmployee INT NOT NULL,
Name VARCHAR(20) NOT NULL,
location_id INT NOT NULL,
email VARCHAR(45),
CONSTRAINT emp_id_pk PRIMARY KEY(idEmployee),
CONSTRAINT emp_loc_fk FOREIGN KEY(location_id) REFERENCES location(IdLocation);
Insert:
INSERT INTO factory(factory_id_sequence.NEXTVAL,43,23);
And i got this error..I can't see what's mistake.
Thanks a lot!
You need to have the VALUES keyword in the insert statement:
INSERT INTO factory VALUES (factory_id_sequence.NEXTVAL,43,23);

Creating table in Oracle 11g with multiple foreign keys with - ORA-00922: missing or invalid option

I followed the previous instruction of placing commas after each of the CONSTRAINTS. However, on this table, it's giving me the following error message:
ORA-02264: name already used by an existing constraint
All the foreign key tables that are associated with this table are created successfully. What is missing here?
CREATE TABLE FIELD (
ENCT_ID VARCHAR2(25) NOT NULL,
FLD_NUM NUMBER NOT NULL,
FLD_DESC VARCHAR2(50) NOT NULL,
SYMPT_CODE VARCHAR2(25),
DIAG_CODE VARCHAR2(25),
TEST_ID VARCHAR2(25),
RM_ID VARCHAR2(10) NOT NULL,
AX_CODE VARCHAR2(25) NOT NULL,
PROV_ID VARCHAR2(25) NOT NULL,
MED_NDC VARCHAR2(25),
PRIMARY KEY (ENCT_ID, FLD_NUM),
CONSTRAINT FK_ENCOUNTER FOREIGN KEY (ENCT_ID) REFERENCES ENCOUNTER(ENCT_ID),
CONSTRAINT FK_SYMPTOM FOREIGN KEY (SYMPT_CODE) REFERENCES SYMPTOM(SYMPT_CODE),
CONSTRAINT FK_DIAGNOSIS FOREIGN KEY (DIAG_CODE) REFERENCES DIAGNOSIS(DIAG_CODE),
CONSTRAINT FK_TEST FOREIGN KEY (TEST_ID) REFERENCES TEST(TEST_ID),
CONSTRAINT FK_ROOM FOREIGN KEY (RM_ID) REFERENCES ROOM(RM_ID),
CONSTRAINT FK_ASSESSMENT FOREIGN KEY (AX_CODE) REFERENCES ASSESSMENT(AX_CODE),
CONSTRAINT FK_PROVIDER FOREIGN KEY (PROV_ID) REFERENCES PROVIDER(PROV_ID),
CONSTRAINT FK_MEDICATION FOREIGN KEY (MED_NDC) REFERENCES MEDICATION(MED_NDC));
CREATE TABLE FIELD (
ENCT_ID VARCHAR2(25) PRIMARY KEY,
FLD_NUM NUMBER PRIMARY KEY,
FLD_DESC VARCHAR2(50) NOT NULL,...
Remove any one primary key. It will be the index for the table. Like a School text books have only one index, same way, every table will have only one primary key.

Resources