Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change the name of constraint or drop it that has dot (.) inside its name?

I have created a constraint named version.pk while back ago on some table. Now, I want to drop it using the following query

alter table user.some_table drop constraint version.pk

However it’s giving me an error saying ORA-01735: invalid ALTER TABLE option. I think it’s because the constraint has dot (.) inside it and oracle does not recognize the query as a valid one. I wanted to change the name of the constraint to version_pk with the following query

alter table user.some_table rename constraint version.pk to version_pk

But again the same issue this time with different error ORA-00946: missing TO keyword . But I think the reason is the same, as it is not a valid query.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

One solution that I have found for primary key type of constraints is this

alter table user.some_table drop primary key

But my constraint is foreign key type. Is there any way to refer constraint name as a literal text, something like 'version.pk', so that query remains valid?

>Solution :

Use a quoted identifier:

alter table user.some_table drop constraint "VERSION.PK";

Note: when you use quoted identifiers, you MUST use the correct case for all characters in the identifier as "VERSION.PK", "version.pk" and "VeRsIoN.pK" are three different identifiers.

Note: Single quotes are for text literals and double quotes are for quoted identifiers.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading