Can someone please help me with the following Oracle SQL Statement. I am getting an error:
ORA-00905: missing keyword
ALTER TABLE loan_transaction_codes
ADD FOREIGN KEY (non_accrual_debit_code)
REFERENCES dbo.general_ledger_accounts (gl_account_no)
ON UPDATE NO ACTION
ON DELETE NO ACTION
Oracle Database does not have an ON UPDATE clause in referential constraint syntax, it only has an ON DELETE (optional) clause; and the only options for ON DELETE are CASCADE and SET NULL, there is no NO ACTION option. Please refer to the Oracle documentation, which is very easy to find and read.
Related
I have an issue and get this SQL error that I can't identify the source of. It's blocking the delete API and nothing is clear about it on the internet:
The DELETE statement conflicted with the REFERENCE constraint "FK_re". The conflict occurred in database "test", table "dbo.MatchingTable", column 'M_Id'.
The statement has been terminated. The DELETE statement conflicted with the REFERENCE constraint "FK_re". The conflict occurred in database "test", table "dbo.MatchingTable", column 'M_Id'.
The DELETE statement conflicted with the REFERENCE constraint "FK_re"
this means you can't delete what you want to because there is a foreign key reference.
The tables are linked by a piece of data in certain column, and SQL is warning you that if you do that the link will be to nothing.
This is one of the strengths of SQL data integrity.
I already have my tables full of data, I am trying to add a constraint to only allow letters to be entered into the attribute I have named as studentfname. I have tried various different REGEXP but cannot seem to get any to work without getting an error when inserting them.
Im not sure if its a syntax error or what!
Edit: Here is what I have tried and the error I am getting:
ALTER TABLE STUDENT
ADD CONSTRAINT
check_name
CHECK(regexp_like(studentfname,'^[A-Za-z''-]+$'));
Error:
QL Error: ORA-02293: cannot validate (JEIGH7.CHECK_NAME) - check constraint violated
02293. 00000 - "cannot validate (%s.%s) - check constraint violated"
*Cause: an alter table operation tried to validate a check constraint to
populated table that had nocomplying values.
*Action: Obvious
Apparently you can try to run this below query to check if any non integral data resides in the above mentioned column which is preventing you from applying a check constraints. Once you get the output from this query try UPDATING/DELETING the row and then apply the constraint. Hope this helps.
SELECT studentfname nm FROM STUDENT a
WHERE NOT regexp_like(a.nm,'^[A-Za-z''-]+$');
Here is ERD model of my DB:
Here is create table codes i used so far:
pastebin
I have created all tables and now I'm trying to alter them to create foreign keys, but this alter doesn't work.
Alter table uskladnena_surovina add foreign key (datum_spotreby,id_dodavatela,id_suroviny) references ponukana_surovina (datum_spotreby,id_dodavatela,id_suroviny)
/
It says:
"DATUM_SPOTREBY":
00904. 00000 - "%s: invalid identifier"
You need to tell Oracle that you want to create a constraint. To do this, you need to specify add constraint after alter table .... If you don't tell Oracle what you want to add to the table, it assumes you want to add a new column.
Try
Alter table uskladnena_surovina add constraint constraint_name foreign key (datum_spotreby,id_dodavatela,id_suroviny) references ponukana_surovina (datum_spotreby,id_dodavatela,id_suroviny)
/
You also have to give the constraint a name. Feel free to change constraint_name.
Oh sorry guys,
i forgot to add datum_Spotreby into uskladnena_surovina so obviously it couldnt work, now it works
I'm having a problem with an SQL statement.
I want to activate a "ON UPDATE CASCADE" behavior for a foreign key in a table with this statement :
ALTER TABLE "DB"."RECORD" ADD CONSTRAINT "RECORD_PT_OUTIL_FK1" FOREIGN KEY ("CDE_PO")
REFERENCES "DB"."PT_OUTIL" ("CDE_PO") ON UPDATE CASCADE ENABLE;
But when i run the statement in Oracle Developer, i just get this error message : "ORA-00905 : missing keyword"
I can't find what could be this missing keyword, i tried several changes but always the same error occurs.
I reuse a code generated by Oracle Developer it self and just modify it with what i want.
This is the generated code :
ALTER TABLE "DB"."RECORD" ADD CONSTRAINT "RECORD_PT_OUTIL_FK1" FOREIGN KEY ("CDE_PO")
REFERENCES "DB"."PT_OUTIL" ("CDE_PO") ON DELETE CASCADE DISABLE;
See, i just change the end of it.
So what's the matter here ? Am i missing something ? (please don't bash if it's something obvious :) )
Thx !
Oracle does not support the ON UPDATE clause for foreign keys.
See the description of the REFERENCES clause in the manual:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/clauses002.htm#CJAIHHGC
Try by removing the DISABLE/ ENABLE at the end of your command
As per the ADD CONSTRAINT reference, there doesnt seem to be any "Enable / Disable" as part of the command.
I think it is something that your Oracle Developer is adding at the end (it being part of Oracle Syntax) and it might be causing the problem!!
I need to update an existing constraint in Oracle database to add a new column there.
ALTER TABLE MY_PARTNER_DETAILS
MODIFY CONSTRAINT UQ_MY_PARTNER_DETAILS
UNIQUE(PARTNER_CODE,PGOOD_CODE,SITE_CODE,PARTNER_PLACEMENT,PARTNER_PARTICIPATION)
Gives the error:
Error at line 1
ORA-00933: SQL command not properly ended
What's the problem with that?
You should drop and recreate the constraint. modify constraint allows you to change constraint's state not definition.
See: Oracle Docs