Key in View for two primary keys tables
Hi
I have some view joining LIKP and LIPS:
LIKP - Primary Key MANDT, VBELN
LIPS - Primary Key MANDT, VBELN, POSR
The Key for the LIKP-LIPS View is:
MANDT LIKP
VBELN LIKP
MANDT_I LIPS
VBELN_I LIPS
POSNR_I LIPS
So, for that Key, if i need to acces a specify LIPS detail record , must i fill all the keys in the where (filling VBELN twice) like this:
WHERE VBELN = vbvalue AND VBELN_I = vbvalue AND POSNR_I = posvalue ?
How must i make the Select for acces this View using its Key ?
Regards
Frank
Hi
Just as I said:
SELECT SINGLE * FROM Z<VIEW> WHERE VBELN = <VBELN>
AND POSNR_I = <POSNR>.
Anyway it's should be better you correct the view deleting the field MANDT_I, VBELN_I, if you can't, I believe the select above works fine.
VIEW FIELDS:
View Field Table Field Key
MANDT LIKP MANDT Yes
VBELN LIKP VBELN Yes
<b>MANDT_I LIPS MANDT Yes <----- WRONG
VBELN_I LIPS VBELN Yes <----- WRONG</b>
POSNR_I LIPS POSNR Yes
ERNAM LIKP ERNAM
ERDAT LIKP ERDAT
VKORG LIKP VKORG
PSTYV_I LIPS PSTYV
MATNR_I LIPS MATNR
WERKS_I LIPS WERKS
LGORT_I LIPS LGORT
By this defintion the field MANDT and VBELN are only twice, but it doesn't mean the record is double in the VIEW.
So it you have the delivery 100 with 3 items in the client 200, in the view you'll see:
Record 1: MANDT = 200
VBELN = 0000000100
MANDT_I = 200
VBELN_I = 0000000100
POSNR_I = 000010
Record 2: MANDT = 200
VBELN = 0000000100
MANDT_I = 200
VBELN_I = 0000000100
POSNR_I = 000020
Record 3: MANDT = 200
VBELN = 0000000100
MANDT_I = 200
VBELN_I = 0000000100
POSNR_I = 000030
Max
Similar Messages
-
How to do hibernate mapping for table or view without a primary key
Hi,
Anyone knows how to do hibernate mapping for table or view without a primary key?
thanks.
ccor you can make all column primary key .Anybody seriously considering that as a good idea should understand the implications:
1. this requires that each row be unique - that's a minor issue normally, but can be a significant problem in some cases
2. in practically all databases, a primary key constraint creates a unique index - this has many implications:
a) in most databases, the index stores a copy of the column data that is indexed - this suggestion therefore more than doubles the data storage required for the data
b) whenever an indexed column is changed, the index has to be maintained - this suggestion then more than doubles the work that each UPDATE statement has to do, since both the table and the index have to be maintained for any UPDATE at all
This might work OK for toy projects, but it doesn't scale well at all... -
How do I obtain the next number for a Primary Key using an ADF View Object?
I have two separate View Objects (A & B) for the same Entity Object. View Object A does a SELECT on all of the fields in the table. This View Object is where I execute my adds and updates. View Object B is only used to retrieve the next number for the primary key. This is done so that when I add a row to the database, I always get the max number of the primary key and add one to it. I accomplished this by setting the SQL mode to Expert and using the SQL: "SELECT MAX(NBR) AS MAX_NUMBER FROM TABLE_1". This may be overkill having a seperate View Object for this, but so far this is the only way I have found to obtain the next number. However, I have discovered that this way does not always work.
The problem I'm running into is when I try to add multiple records to View Object A without committing the transaction between each add. Because View Object B is disconnected from View Object A, the MAX_NUMBER of View Object B comes back with the same number for each add I do on View Object A. So I know I must retrieve the MAX_NUMBER from View Object A.
I've tried using the following code in my Table1ViewImpl class:
this.setQuery("SELECT MAX(Table1.NBR) AS MAX_NUMBER FROM TABLE_1 Table1");
this.executeQuery();
The view object now has what I want, but I have yet to figure a way to extract the MAX_NUMBER out of the View Object. I've also looked into using the method addDynamicAttribute() but I can't figure out any way to set the attribute with the MAX_NUMBER.
I can't be the only one trying to retrieve the next number from a database table using ADF. Can anyone help me with this? FYI - I'm using JDev 10.1.3 EA.You missing the point.
On a multi-user db knowing the next highest number doesn't guarantee the number will be available when it comes time to commit the record. You can prove this to yourself by opening two instances of your app and do whatever you do to add a new record to your VO. Both will assume the same number, and when you commit an error will be generated
You must use sequences to avoid the possibility of duplicate keys. If you are trying to avoid gaps in your numbering then you need to convince yourself why this is necessary. -
We are at the end of completing a project and we ran into a last minute bug. We are using two primary keys on a table to form a unique key. The problem we have is the program hangs up and gives us the following error,
ORA-20001: Error in DML: p_rowid=CUA, p_alt_rowid=SIT_ID, p_rowid2=, p_alt_rowid2=. ORA-01422: exact fetch returns more than requested number of rows,
probably meaning we only have one key setup in the DML
processing when our table has two.
we created a process with the Primary key set up in the DML but how does the secondary key column value work and is that what it's used for,because we tryed with no success. Is there a way around this problem without having to change our table by inserting only one primary key.
Thanks in advance.
GarryI am facing a similar problem , I used the two primary keys for navigating to the form page (forms with reports) so that the form page may display distinct records.
Its not posing any error but its not showing the value of other columns associated with that record.
Only the columns contained in the page item in the form page , that's are used as primary keys or that have been specified in the navigation part of the report page, are being shown ,
Like for example I have got 5 columns
a,b,c,d,e out of which a and b are my primary keys .
I am using these to fetch values in the form page of forms with reports.
We can specify three keys at the most , in my case I am having two , if in place of the third key I specify some column then in the form page it displays the correct record details of the three columns specified( 2 keys and one simple column), and it doesn't displays the value of other columns.
Please help me out of this . -
How to specify tablespace for a primary key inde in create table statement
How to specify the tablespace for a primary key index in a create table statement?
Does the following statement is right?
CREATE TABLE 'GPS'||TO_CHAR(SYSDATE+1,'YYYYMMDD')
("ID" NUMBER(10,0) NOT NULL ENABLE,
"IP_ADDRESS" VARCHAR2(32 BYTE),
"EQUIPMENT_ID" VARCHAR2(32 BYTE),
"PACKET_DT" DATE,
"PACKET" VARCHAR2(255 BYTE),
"PACKET_FORMAT" VARCHAR2(32 BYTE),
"SAVED_TIME" DATE DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "UDP_LOG_PK" PRIMARY KEY ("ID") TABLESPACE "INDEX_DATA"
TABLESPACE "SBM_DATA"; Thank you
Edited by: qkc on 09-Nov-2009 13:42As orafad indicated, you'll have to use the USING INDEX clause from the documentation, i.e.
SQL> ed
Wrote file afiedt.buf
1 CREATE TABLE GPS
2 ("ID" NUMBER(10,0) NOT NULL ENABLE,
3 "IP_ADDRESS" VARCHAR2(32 BYTE),
4 "EQUIPMENT_ID" VARCHAR2(32 BYTE),
5 "PACKET_DT" DATE,
6 "PACKET" VARCHAR2(255 BYTE),
7 "PACKET_FORMAT" VARCHAR2(32 BYTE),
8 "SAVED_TIME" DATE DEFAULT CURRENT_TIMESTAMP,
9 CONSTRAINT "UDP_LOG_PK" PRIMARY KEY ("ID") USING INDEX TABLESP
ACE "USERS"
10 )
11* TABLESPACE "USERS"
SQL> /
Table created.Justin -
EF beta - views with no primary key
When importing views into the entity framework designer, it often gives this error (in the edmx file only; no error is shown in the UI):
warning 6013: The table/view '[view name]' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.
I don't want to cloud the issue by going into the details of the views in question; there will always be views where no PK can be inferred automatically, for many reasons. And I am quite happy to define the key fields myself after import. The problem is that it can't be imported at all. So my question to the ODP.NET developers is: can you just import it, and leave me to define the PK?
The workaround I am using is:
1) define a temp table of the same structure
2) temporarily recreate the view as "select * from [temp table]"
3) update the model from database
3) recreate the proper view
But it's a pain. I have to remember to do that every time I update the model from the database. If I forget, it wipes the mapping, and I have to redefine it manually, field by field.Unfortunately there is still a problem, in a minority of cases:
Error 75: Key Part: '[field name]' for type [view name] is not valid. All parts of the key must be non nullable.
This happens when the view field is not marked "not null". Generally it flows through from the underlying table field. But one of my views involves a "union all". The underlying table fields are marked "not null" but it doesn't make it through the "union all". The view has a primary key, but still the error.
I would rather it just trust me that primary key fields will never be null. -
Exception: non-read-only mapping defined for the primary key field
Hello.
I'm new to Oracle and I created Java EE Web Project.
And I created entities from tableA, tableB, tableC from my database.
tableA has foreign key to tableB and has unidirectional Many-to-One relationship. tableC has two primary keys and one of these is foreign key to primary key in tableA. tableC also has unidirection Many-to-One relationship to tableA.
Then I created session bean and data control from it, in design window, created read-only table from tableA.
And I selected columns in tableA and also in tableB.
I ran the application and saw the following exception in log window.
Local Exception Stack:
Exception [EclipseLink-46] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: There should be one non-read-only mapping defined for the primary key field [tableC.tableA_ID].
Descriptor: RelationalDescriptor(mypack.tableC --> [DatabaseTable(tableC)])
tableA_ID is a primary key in tableA.
How can I solve this error?
Please help me.
Edited by: 900471 on 2011. 12. 3 오전 5:32
Edited by: 900471 on 2011. 12. 3 오전 5:33
Edited by: 900471 on 2011. 12. 3 오전 5:33
Edited by: 900471 on 2011. 12. 3 오전 5:34There are not enough details to be sure since you have not provided the mappings. From just the error, it looks like you are using the tableC.tableA_ID field as the foreign key in the ManyToOne relationship to A, but have marked it as insertable=false, writeable=false, meaning that it cannot be updated or used for inserts.
Either make it writable (set the settings to true), or add another basic mapping/attribute in the entity for TableC that maps to the field which you can use to set when you insert a new tableC entity. A simple example is available at
http://wiki.eclipse.org/EclipseLink/Examples/JPA/2.0/DerivedIdentifiers
Best Regards,
Chris -
Creating a script for a PRIMARY KEY USING INDEX SORT doesn't work
Probably a bug.
h1. Environment
Application: Oracle SQL Developer Data Modeler
Version: 3.0.0.655
h1. Test Case:
1. Create a new table TRANSACTIONS with some columns.
2. Mark one of numeric columns as the primary key - PK_TRANSACTIONS.
3. Go to Physical Models and create new Oracle Database 11g.
4. Go to Physical Models -> Oracle Database 11g -> Tables -> TRANSACTIONS -> Primary Keys -> PK_TRANSACTIONS -> Properties:
a) on General tab set Using Index to BY INDEX NAME
b) on Using Index tab choose a tablespace
c) on Using Index tab set Index Sort to SORTED.
5. Export the schema to DDL script. For the primary key you will get something like this:
ALTER TABLE TRANSACTION
ADD CONSTRAINT PK_TRANSACTION PRIMARY KEY ( TRAN_ID ) DEFERRABLE
USING INDEX
PCTFREE 10
MAXTRANS 255
TABLESPACE TBSPC_INDX
LOGGING
STORAGE (
INITIAL 65536
NEXT 1048576
PCTINCREASE 0
MINEXTENTS 1
MAXEXTENTS 2147483645
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
) SORTED
h1. Reason of failure
The script will fail because SORTED is not allowed here. It should be SORT.
Additionally, the default behaviour for Data Modeler is to set Index Sort to NO but default setting for Oracle database 11g is SORT. Shouldn't Data Modeler use SORT as the default value?
Edited by: user7420841 on 2011-05-07 03:15Hi,
Thanks for reporting this problem. As you say, it should be SORT rather than SORTED. I have logged a bug on this.
I also agree that, for consistency with the database default, it would be better to have SORT as the default in Data Modeler.
David -
Duplicate entries for same primary key
Hi,
I am facing problem to insert 2 or more than 2 entries for same PRIMARY KEY in the database table.
As I know that we cant do that. But Client has given me the XL sheet which contains 2 entries for same primary key. How can it be done? Please let me know how can I insert 2 data for same primary key in database table.
Waiting for your answers.
Thanks in advance.
Regards,
PrasannaHi,
You can achieve this .... All you have to do is to add a new field (a Sequence Number ) to the table. This number will be incremented for each duplicate primary keys. For example....
Consider the excel file has duplicate entries 3 primary keys. Now you add a new field named Sequence Number in your DB Table.....
When you load the data into Database...then the records will look like this...
Key1 Key2 Key3 Seq
A B C 1
A B C 2
A B D 1
A B D 2
A C D 1
A C E 1
and so on...
I hope this solves your purpose.....
Whenever there are duplicate entries, such as the one mentioned in your scenario, then a new field can be added in Database. This field acts like a count or sequence number.... Thus you can maintain unique records.
Regards,
Vara
Regards,
Vara -
Is this good approach for generating Primary Keys ?
Hi,
All our EJBs are state less Session Beans.
We have created a state less Session(name SequenceEJB) for getting Primary Key.
Thre is a method,
int getSequenceNumber(String tableName,String fieldName) in SequenceEJB. And the following query is used in the above said method.
SELECT MAX("+fieldName+") ID FROM "+tableName
Each EJB will lookup SequenceEJB, and call the above said method for getting sequence number.
Is this approach sclable ?
Can we proceed by this approach ?
Thanks in advance
SrinivasAs long as you are in EJB, synchronization won't help you because it is not permitted by the EJB spec.
If you can go with JDBC 3.0 / Java 1.4, the statement interface supportes generated keys. See http://java.sun.com/j2se/1.4/docs/api/java/sql/Statement.html.
If you cannot go with JDBC 3.0 / Java 1.4, you can implement the key-generation db-specific (e.g. using oracle sequences for oracle tables, and whatever exists for DB2, SQL Server etc.) That of course requires special support for all databases, but at least you can run your app with different databases.
Or you can try to do it the following way, using a separate table for the keys.
ResultSet rs = statement.executeQuery("select id from mySequences");
oldId = rs.getInt(1);
newId = oldId + 1
int updatedRows = statement.executeQuery("update mySequences set id = newId where id = oldId");
if(updatedRows == 1) {
// succesful
} else {
// not sucessful, somebody else has already retrieve this id; do something like Thread.sleep() and retry
}This way, the database does the actual synchronization between the processes (each process sees the same data in the tables), and you implement the retry logic. -
Checking for duplicate primary keys on row inserts
Checking for duplicate primary keys on row inserts
I have a situation where I will be making bulk table inserts knowing that the primary key value will in some cases already exist. In this is the case I simply want to ignore the duplicate inserts.
Should I be performing a sub-query on the table and using a statement like:
where not exist in
Or is there a cleaner way of discarding or checking for duplicates on insert.
My concerns were mainly one of performance, as my routine will be inserting a few thousand rows in its operation.The MERGE commnad is a good option when a large percentage of the data will exist in the target because it is much more efficient to attempt to update then insert when the update affects zero rows than capture an error and convert it to an update.
However, since in this case it would appear that only a few rows will alreadys exist and we want to ignore the duplicates when they exist then
begin
insert
exception
when dup_value_in_index then null;
end
would be the way to code this one. The bulk insert version has in 9.2 the ability to store the errors so that they can all be handled at once which means the rest of the array insert can work.
HTH -- Mark D Powell -- -
How to pass values for compound primary keys for updating the record in db.
i have a entity bean in my ejb with two primary keys to it...eg. roleid,rolename...
when iam retriving the record i use only one primary key ...so again to modify and update he same record which i retrived is a pbm..
i cannot set the values for the compoundpk,,,
but i can do the update for the bean with single primary key..
i need to know how to pass the values/parameters for the coumpound primary key in my update method...
thanx in advance...
Arjun.GI istantiated a object for the pk class and assign the values for the primary key fields...
Arjun.G -
How to change the source type for a primary key on a form?
Hi,
At the time of creating a form, I had set the source type for the primary key to an existing sequence.
Now I want to change the source to a trigger.
Can anyone suggest how to do it?
Thanks in advance,
AnnieAnnie:
Define the trigger and then delete the page process named 'Get PK'
Varad -
[Incoming Payments for WTax] Primary Key not exist in DB
While performing the TDS upgrade, I am getting an error message as "[Incoming Payments for WTax] Primary Key not exist in DB".
I have checked that the sheet conforms to the instructions provided in the Upgrade guide but am not able to resolve this.
Any ideas?
Regards,
GyaneshHi,
It seems to be some field in the TDS upload Excel sheet which has primary key field not having the correct value.
Double check the same where Primary Key if linked with some value in other sheet, enter the same.
Kind Regards,
Jitin
SAP Business One Forum Team -
Does a foreign key have to be a primary key
Hey all.I was checking on the database code written by sambapos.To my surprise, I found a foreign key that is not a primary key anywhere.
Is that possible?
If, so why?
I am really astonished.Limitations and Restrictions
A foreign key constraint does not have to be linked only to a primary key constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table.
When a value other than NULL is entered into the column of a FOREIGN KEY constraint, the value must exist in the referenced column; otherwise, a foreign key violation error message is returned. To make sure that all values of a composite foreign key constraint
are verified, specify NOT NULL on all the participating columns.
FOREIGN KEY constraints can reference only tables within the same database on the same server. Cross-database referential integrity must be implemented through triggers. For more information, see
CREATE TRIGGER (Transact-SQL).
FOREIGN KEY constraints can reference another column in the same table. This is referred to as a self-reference.
A FOREIGN KEY constraint specified at the column level can list only one reference column. This column must have the same data type as the column on which the constraint is defined.
A FOREIGN KEY constraint specified at the table level must have the same number of reference columns as the number of columns in the constraint column list. The data type of each reference column must also be the same as the corresponding column in the column
list.
The Database Engine does not have a predefined limit on either the number of FOREIGN KEY constraints a table can contain that reference other tables, or the number of FOREIGN KEY constraints that are owned by other tables that reference a specific table.
Nevertheless, the actual number of FOREIGN KEY constraints that can be used is limited by the hardware configuration and by the design of the database and application. We recommend that a table contain no more than 253 FOREIGN KEY constraints, and that it
be referenced by no more than 253 FOREIGN KEY constraints.
FOREIGN KEY constraints are not enforced on temporary tables.
If a foreign key is defined on a CLR user-defined type column, the implementation of the type must support binary ordering. For more information, see
CLR User-Defined Types.
A column of type varchar(max) can participate in a FOREIGN KEY constraint only if the primary key it references is also defined as type
varchar(max).
Read this article
http://msdn.microsoft.com/en-us/library/ms189049.aspx
Regards, Ashwin Menon My Blog - http:\\sqllearnings.com
Maybe you are looking for
-
My old iPod Nano says to use iTunes to restore and I've followed all suggested help steps, but I can't get it into disk mode nor can I get it to show in my computer or in iTunes. I have the latest version of iTunes. Windows has all the most recent
-
iDVD ejects the dvd disc one minute early, before burning is completed. Why? What can I do to fix this? I have checked project via mapping and there are no problems with it. I have previewed the entire project and it runs fine.
-
Abap Lists - Printing - defining font and CPI and applying to printed text
Hi, I am trying to define some forms for matrix printing. I should change the font type, and CPI. We will print ABAP Lists. I see my fonts (courier, 100, 12CPI, Prnt.Ctrl SF005) are defined in SE73. In SPAD - device type (choose spec. one) u2013 Prin
-
On a chart, I only want to have every other or every third value label to be printed instead of all of them. When all of them are printed, the numbers overlap with the next value. (The digits are 6 figures long.) Thanks Ray
-
Why has the microphone in my iP4 stopped working?
My iPhone randomly cut out during a call, and now no one can hear me when I call!