Oracle database 23ai: Error ORA-02264 occurs, but I can neither find a constraint with the specified name nor drop one

I am using Oracle database 23ai, free version, along with the PL/SQL developper of Allround Automations. I am getting the error ORA-02264 and though I understand its meaning (an already active constraint with same name was found where assigning the same name to two constraints is forbidden), I don’t understand why this error pops up in my case.

I am trying the following code:

CREATE TABLE nations (
nations_id INTEGER GENERATED BY DEFAULT AS IDENTITY,
name NVARCHAR2(255) NOT NULL,
continent NVARCHAR2(20) NOT NULL,
habitants_at_2024 INTEGER,
capital NVARCHAR2(255) NOT NULL,
CONSTRAINT pk_nations PRIMARY KEY(nations_id),
CONSTRAINT unique_nation_name UNIQUE(name)
);
-- cities
CREATE TABLE cities(
cities_id INTEGER GENERATED BY DEFAULT AS IDENTITY,
name NVARCHAR2(255) NOT NULL,
country NVARCHAR2(255),
CONSTRAINT pk_cities PRIMARY KEY(cities_id),
CONSTRAINT unique_city_name UNIQUE(name),
CONSTRAINT fk_country FOREIGN KEY(country) REFERENCES nations(name)
);
ALTER TABLE nations ADD CONSTRAINT fk_capital FOREIGN KEY(capital) REFERENCES cities(name);

The error message:

ORA-02264: name already used by an existing constraint

pops up on the line with the ALTER TABLE statement.

However, I am quite sure there shouldn’t be another constraint with the name fk_capital. To verify this, I tried the following as suggested in this question

SELECT *
  FROM all_constraints
 WHERE table_name = UPPER('table_name'); 

The command works fine, but I cannot find the constraint name in the resulting table either. What’s more, I tried the following:

ALTER TABLE nations DROP CONSTRAINT fk_capital;
ALTER TABLE nations ADD CONSTRAINT fk_capital FOREIGN KEY(capital) REFERENCES cities(name);

The attempt to drop the constraint fails with the error message ORA-02443, which suggests there is no constraint with the name fk_capital. Right after that, ORA-02264 pops up again, indicating once more the name would already be in use. I made sure there is no typo – the code you’re seeing is copy-pasted. Can someone tell me where I am going wrong?

Thanks in advance for all answers!

PS.: I found another post suggesting that I can find the constraint-name using

SELECT owner, constraint_type, table_name
from user_constraints
where constraint_name = 'fk_capital';

but the resulting table is empty in my case.

New contributor

new_newbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

The names in Oracle’s data dictionary appear in uppercase. Instead of querying for fk_capital, you should query for FK_CAPITAL.

SELECT owner, constraint_type, table_name
FROM   user_constraints
WHERE  constraint_name = 'FK_CAPITAL';

1

When you execute queries to check for the constraint fk_capital, it may not return results because Oracle treats it as FK_CAPITAL internally.

Steps to Resolve the Issue:

  1. Verify the Constraint Name: Run the following query to check for constraints in uppercase:

SELECT owner, constraint_type, table_name
FROM user_constraints
WHERE constraint_name = ‘FK_CAPITAL’;

  1. Check All Constraints for the Table: If the above query doesn’t work, list all constraints for the nations table to confirm its existence:

SELECT constraint_name, constraint_type
FROM user_constraints
WHERE table_name = UPPER(‘NATIONS’);

  1. Dropping the Constraint (If Necessary): If the fk_capital constraint exists, you can drop it using:

ALTER TABLE nations DROP CONSTRAINT fk_capital;

  1. Recreate the Constraint: Once confirmed or dropped, you can recreate the constraint:

ALTER TABLE nations
ADD CONSTRAINT fk_capital FOREIGN KEY (capital) REFERENCES cities(name);

Additional Tips:

Ensure No Duplicate Constraints: Confirm that no other constraint is using the name fk_capital across different schemas.

SELECT owner, table_name, constraint_name
FROM all_constraints
WHERE constraint_name = ‘FK_CAPITAL’;

Schema Ownership: If you are working in a multi-schema environment, ensure you are querying the correct schema by prefixing the table name with the schema name (e.g., schema_name.nations).

If the issue persists, it might be related to the Oracle free version limitations or a database bug.

New contributor

Rahul Thakur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật