name already used by an existing constraint [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Create Table Resources_user
(
Resources_userID INTEGER NOT NULL,
Resources_ID INTEGER NOT NULL,
User_ID INTEGER NOT NULL,
Data Accessed DATE,
CONSTRAINT PK_Resources_user PRIMARY KEY (Resources_userID),
constraint fk_Resources_user1 Foreign key (Resources_ID ) references Resources,
constraint fk_Resources_user2 Foreign key (User_ID) references User1);
Create table Staff_Position
(
Staff_Position_ID INTEGER NOT NULL,
Position_ID INTEGER NOT NULL,
User_ID INTEGER NOT NULL,
CONSTRAINT PK_Staff_Position PRIMARY KEY (Staff_Position_ID),
Constraint fk_Staff_Position1 foreign key (Position_ID) references position,
Constraint fk_Staff_Position2 foreign key (User_ID) references User1);
Thank you the problem been solved, I realized that i need to number my foreign keys for avoiding the error of repeating .

Your foreign key constraints are incomplete. You did not specify a field. This:
, constraint fk_Resources_user Foreign key (Resources_ID ) references Resources
should be something like this:
, constraint fk_Resources_user Foreign key (Resources_ID )
references Resources (resources_id)
Some Oracle error messages are misleading. This is one of them.
Edit Starts Here
You also have duplicate constraint names for your foreign keys. You will likely get a message indicating such once the other problems are resolved.

Related

reference primary key from another table [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 10 months ago.
Improve this question
I have to create 2 tables.
the first one
CREATE TABLE orders
( order_id number(10) NOT NULL,
order_name varchar2(50) NOT NULL,
payment_id number(10) NOT NULL,
CONSTRAINT order_id PRIMARY KEY (order_id),
);
and when creating the second one I got this error
ORA-02270: no matching unique or primary key for this column-list
CREATE TABLE payment
(
payments_id number(10) NOT NULL,
payment_name varchar(50) NOT NULL,
CONSTRAINT payments_id PRIMARY KEY (payments_id),
FOREIGN KEY (payments_id) REFERENCES orders(payment_id)
);
not sure what I'm doing wrong
please help
You need to reference a UNIQUE or PRIMARY KEY column. The payment_id column does not have one of those constraints on it.
From the Oracle constraint documentation:
Foreign Key Constraints
A foreign key constraint (also called a referential integrity constraint) designates a column as the foreign key and establishes a relationship between that foreign key and a specified primary or unique key, called the referenced key.
Instead, you can add an order_id column to your table:
CREATE TABLE orders(
order_id NUMBER(10) NOT NULL,
order_name VARCHAR2(50) NOT NULL,
CONSTRAINT orders__order_id__pk PRIMARY KEY (order_id)
);
CREATE TABLE payment(
payments_id NUMBER(10) NOT NULL,
payment_name VARCHAR2(50) NOT NULL,
order_id NOT NULL,
CONSTRAINT payment__payments_id__pk PRIMARY KEY (payments_id),
CONSTRAINT payment__order_id__fk FOREIGN KEY (order_id)
REFERENCES orders (order_id)
);
db<>fiddle here

ORA-00904: : invalid identifier in Oracle Life database [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Even i run this as script, i got error. first i didnt use 'wrent_id' and still got error.
CREATE TABLE want_renting (
'wrent_id' int NOT NULL PRIMARY KEY,
'property_id' int,
'client_id' int,
'agent_id' int,
'wrent_date' date,
'expired_date' date,
CONSTRAINT 'fk_property' FOREIGN KEY ('property_id') REFERENCES 'property'('property_id'),
CONSTRAINT 'fk_client' FOREIGN KEY ('client_id') REFERENCES 'clients'('client_id'),
CONSTRAINT 'fk_agent' FOREIGN KEY ('agent_id') REFERENCES 'agents'('agent_id'),
);
ORA-00904: : invalid identifier
Remove quotes from your query. Quotes is used to define a string and not during table creation.
CREATE TABLE want_renting (
wrent_id int NOT NULL PRIMARY KEY,
property_id int,
client_id int,
agent_id int,
wrent_date date,
expired_date date,
CONSTRAINT fk_property FOREIGN KEY (property_id) REFERENCES
property(property_id),
CONSTRAINT fk_client FOREIGN KEY (client_id) REFERENCES clients(client_id),
CONSTRAINT fk_agent FOREIGN KEY (agent_id) REFERENCES agents(agent_id)
);
And make sure you have all other tables referencing the foreign keys.

Trying to create table with 3 foreign keys on ms access [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying to create database where I have 3 tables to keep the data and the forth table to store the actual operations that processes the data. On the operations table I am using 3 foreign keys that referred to the other table but somehow I am able to create the table only with 2 foreign keys but once I add the third foreign key I get an error:
The Sql code for the operations table:
CREATE TABLE Operations
(
operation_Id AUTOINCREMENT PRIMARY KEY,
User_Id INTEGER NOT NULL CONSTRAINT FK_user_ID REFERENCES Users (User_Id),
course_Id INTEGER NOT NULL CONSTRAINT FK_course_ID REFERENCES Courses (Course_Id)
college_Id INTEGER NOT NULL CONSTRAINT FK_college_ID REFERENCES Colleges (college_Id)
)
and the tables with the relationships:
The Error
Note, Once I receive the error it point at the college_Id on the operations table
As #sticky-bit said, There is a missing , in your query right after Courses (Course_Id) see the correct one :
CREATE TABLE Operations
(
operation_Id AUTOINCREMENT PRIMARY KEY,
User_Id INTEGER NOT NULL CONSTRAINT FK_user_ID REFERENCES Users (User_Id),
course_Id INTEGER NOT NULL CONSTRAINT FK_course_ID REFERENCES Courses (Course_Id),
college_Id INTEGER NOT NULL CONSTRAINT FK_college_ID REFERENCES Colleges (college_Id)
)

Tables not creating? Syntax issue? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am currently doing a lab for school and cannot for the life of me figure out why I am getting these errors (2 in particular). The first error thrown to me is that in the table "invoice" the PRIMARY KEY constraint is asking for a second right parentheses. The second error I'm receiving is in the creation of table "invprod" where it is arguing to me that "invno" doesn't actually exist.
I don't know if this is an error in my syntax or otherwise but any help is greatly appreciated.
CREATE TABLE invoice
(invno CHAR(5) NOT NULL
,invdate DATE
,orderno CHAR(5) NOT NULL
,CONSTRAINT invorder FOREIGN KEY (orderno)
REFERENCES salesorder(orderno)
,CONSRAINT pkinvoice PRIMARY KEY (invno)
);
CREATE TABLE invprod
(invno CHAR(5) NOT NULL
,partno CHAR(4) NOT NULL
,shipqty INTEGER CHECK (shipqty>0)
,CONSTRAINT fk1invprod FOREIGN KEY(invno)
REFERENCES invoice(invno)
,CONSTRAINT fk2invprod FOREIGN KEY(partno)
REFERENCES part(partno)
);
You have typo CONSRAINT should be CONSTRAINT:
CREATE TABLE invoice
(
invno CHAR(5) NOT NULL
,invdate DATE
,orderno CHAR(5) NOT NULL
,CONSTRAINT invorder FOREIGN KEY (orderno)
REFERENCES salesorder(orderno)
,CONSTRAINT pkinvoice PRIMARY KEY (invno)
);
SqlFiddleDemo

SQL Error: ORA-00904: "MEBERSHIPID": invalid identifier [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am creating a table whereI'm currently trying to add multiple foreign keys in Oracle
The table scripts is as follows
Create table Member
(
memeberID int Not null Primary Key,
membershipID int Not null,
group_id int not NULL,
Dutycode int not null,
MemberRole varchar(255),
name varchar(255),
last_joined date,
DOB date,
address varchar(255),
CONSTRAINT fk_DutCode FOREIGN KEY (Dutycode)
REFERENCES RaceManagementDuty(Dutycode),
CONSTRAINT fk_GrMemeber FOREIGN KEY (group_id)
REFERENCES Group_member(group_id),
CONSTRAINT fk_Meberships FOREIGN KEY (mebershipID)
REFERENCES Membership(mebershipID)
)
Wandering where I'm going wrong?
Its just a typo error . Change mebershipID to membershipID
CONSTRAINT fk_Meberships FOREIGN KEY (membershipID)
REFERENCES Membership(membershipID)
There is no column mebershipID in table and so throws error