Oracle Materialized View in Entitiy Framework issue - oracle

I have the following issue.
1. I created an Oracle Materialized View which contains the "WITH PRIMARY KEY" clause.
2. when I am trying to add that View to my EDMX, I encounter the following error:
"The table/view 'XXX' does not have a primary key defined and no valid primary key could
be inferred..."
Does anyone know how to add a primary key to Materialized View that can be added to EDMX?
Is this issue solvable ?
thanks,
Hagai

This clause refers to the materialised view including a primary key column from the master table, not that it possesses a primary key itself.
A materialised view is simply metadata on a regular (base) table, so you can perform an alter table command using the name of the the materialised view to create a primary key on the base table.

Related

How to create form/report on a table which has only primary keys?

Im trying to create a form with a report on a table that has only primary keys.
I have a table:
create table WRITE
(
author varchar(5) references AUTHOR (authorcode) ,
book varchar(20) references BOOK (bookid),
primary key(author,book)
);
I'm using APEX Application Builder to create a form on a table with report;
But When I get to the "Select the columns to include in the form" , I have no options to select from because I only have unique primary keys in my table.
Which Apex version is it? I've tried it on apex.oracle.com which uses 19.1 and it doesn't have that problem.
Anyway, two options I can think of:
temporarily drop primary key constraint
then create report + form pages
after you're done, create the primary key constraint once again
create an interactive report (using the wizard)
then create a form, manually adding items
this isn't as easy as it looks like because you'll have to create all processes as well (initialization one, along with automatic row processing)
I presume that the first option is a lot simpler.

ORA-02298 - Parent keys not found when enable constraint

I have a migration script in between 2 different schema database. The script does 3 things:
Disable constraint
Insert record from old schema to new schema
Enable constraint
During enable constraint, it encouter ORA-02298 - Parent keys not found: at the following 2 tables:
ALTER TABLE COUNTRY ENABLE CONSTRAINT COUNTRY_FK1;
ALTER TABLE EMPLOYEE ENABLE CONSTRAINT EMPLOYEE_FK7;
Anything went wrong in the table structure definition of these 2 tables?
It appears you are migrating detail records without ensuring that all the foreign key values are present in the referenced tables. If this is the case then you need to migrate records from REGION#SOURCE_DB into REGION#TARGET_DB before you migrate the COUNTRY records.

Make an Oracle foreign key constraint referencing USER_SEQUENCES(SEQUENCE_NAME)?

I want to create a table with a column that references the name of a sequence I've also created. Ideally, I'd like to have a foreign key constraint that enforces this. I've tried
create table testtable (
sequence_name varchar2(128),
constraint testtableconstr
foreign key (sequence_name)
references user_sequences (sequence_name)
on delete set null
);
but I'm getting a SQL Error: ORA-01031: insufficient privileges. I suspect either this just isn't possible, or I need to add something like on update cascade. What, if anything, can I do to enforce this constraint when I insert rows into this table?
I assume you're trying to build some sort of deployment management system to keep track of your schema objects including sequences.
To do what you ask, you might explore one of the following options:
Run a report after each deployment that compares the values in your table vs. the data dictionary view, and lists any discrepancies.
Create a DDL trigger which does the insert automatically whenever a sequence is created.
Add a trigger to the table which does a query on the sequences view and raises an exception if not found.
I'm somewhat confused at what you are trying to achieve here - a sequence (effectively) only has a single value, the next number to be allocated, not all the values that have been previously allocated.
If you simply want to ensure that an attribute in the relation is populated from the sequence, then a trigger would be the right approach.

Oracle SQL Data Modeler missing a PRIMARY KEY on DDL script export

The diagram has over 40 tables, most of them have a primary key defined.
For some reason there is this one table, which has a primary key defined, but that's being ignored when I export the model to a DDL script.
This is the "offending" key (even though it's checked it is nowhere to be found on the generated DDL script):
Has anybody had the same problem? Any ideas on how to solve it?
[EDIT] This is where the key is defined:
And this is the DDL preview (yes, the primary key shows up there):
This is what happens if I try to generate the DDL for just that table (primary key still not generated):
I was finally able to identify and reproduce the problem.
It was a simple conflict of constraints.
Table MIEMBROS had a mandatory 1 to n relationship (foreign key) from another table on its primary key column and vice-versa (there was a foreign key on MIEMBROS against the other table's primary key).
This kind of relationship between two tables makes it impossible to add a record to any of them: The insert operation will return an error complaining about the foreign key restriction pointing the other table.
Anyway I realized that one of the relationships was 0 to n so I simply unchecked the "mandatory" checkbox on the foreign key definition and everything went fine.
So, in a nutshell: The Data Modeler "fails" silently if you are defining a mutual relationship (two foreign keys, one on each table against the other table) on non nullable unique columns, by not generating the primary key of one of the tables.
Such an odd behavior, if you ask me!
"This kind of relationship between two tables makes it impossible to add a record to any of them: The insert operation will return an error complaining about the foreign key restriction pointing the other table."
Actually, if you have deferred constraints, this is not impossible. The constraints can be enforced, for example, at commit time rather than immediately at insert time.
From the Data Modeler menu under File, I used Export -> DDL File. The keys appeared in the DDL, then when I went back to the diagram and did DDL Preview, it showed all the missing stuff.

Oracle designer - table definition

I've added a new table definition to a project folder and then created a primary key, however when I click on the 'columns' to create a key component its telling me no mandatory columns are in the Table Definition - create one or more mandatory columns. I've gone back to table definitions but I can't see how I do this and then assign columns to the Primary key?
Any help appreciated!!

Resources