Atomic Primary Key or Composite ? Which approach is better ?
Hi all,
I have a table that has its composite primary key (infact foriegn keys of other tables make pk in this table).
But due to large project complexity, i just want to have an atomic primary key, so that i could use a sequence for it, instead of using N foreign keys from other tables. And furthermore, a single column primary key can be easily accessed as foreign key as compared to N columns primary key.
Is it a good approach in general ?
My personal view has certain reservations regarding the atomic primary key in such case. It could lead to a weak database design.
Any suggestion ?
Thanx
Zaaf.
Most large data warehouses implement a 'synthetic' key approach for much the same reasons that you describe. You can still carry the FKs and use them to assist in joining operations, while keeping the size (and complexity) of the primary key down to a manageable size.
There are downsides to this approach - it depends on how the data is most frequently accessed and many other factors. But in general it can work quite well.
Similar Messages
-
Which approach is better- EPMA vs Classic Planning App
Hi Experts,
I question came to me after a big discussion with one of my vendor.
my organization is in process of migrating the V9(9.1.3) environment to EPMV11(11.1.2.1).
Currently we have 4 Classic planning application but we are interested to leverage the EPMA feature of V11 by converting them to EPMA application as they shared some of the dimensions among themself but the vendor who is going to work on that is advising us to keep it in Classic as there is a news of sunsetting EPMA by Oracle to pramote DRM into market. just surprised me that so wanted to know the truthness of the statement.
appreciate your comments.
Regards,
PKThere seems to be lots of rumours floating around about EPMA, how much is true I think you will just have to wait and see, I have my own personal view on the product which I will keep to myself :)
I suppose the decision to switch is to see how much benefit you will get by switching, if you are happy and that moment and everything is working well then I would question why to switch, if you will get much more functionality and benefits then consider it.
Cheers
John
http://john-goodwin.blogspot.com/ -
Which approach is better for remote diagnostics-TCP/Ip or datasockets?
hi,
am working on a remote diagnostics project and would want to know whether to use TCP/IP or data sockets
for my application. any related links regarding the procedure to be
followed while creating and using datasockets would also prove helpful.Hello,
I think you'll find the following resource useful:
TCP/IP and DataSocket LabVIEW User Group Presentation
Link: http://zone.ni.com/devzone/learningcenter.nsf/webmain/E9913176F1E7581C86256E68007DD91E
Description: Download this presentation to learn about the history of TCP/IP and how you can develop TCP/IP applications in LabVIEW. You will also see how to develop client/server LabVIEW applications using DataSocket technology. This LabVIEW User Group Presentaiton includes a PowerPoint presentation along with two step-by-step exercises for a 1/2 day LabVIEW User Group Meeting.
You'll find more information by searching for keywords such as tcp, tcp/ip, and datasocket - many of these are good starting points! There are also shipping examples with LabVIEW which are complete with descriptions. These will help you start programming in addition to the other resources. You can launch the example finder from Help -Find Examples... in LabVIEW - again, searching keywords such as tcp, tcp/ip, or datasocket will give you lists of examples.
I hope this helps!
Best Regards,
JLS
Best,
JLS
Sixclear -
Composite Primary Key needs Unique ID column or no?
Hello Dears ,
I have a table that it's primary key is composite key of two columns , and there are like 5 info columns . You think I shall use the two columns as primary key of this table or create unique ID column .
Example :
Table Employees :
Table Departments :
The problem table is Department Managers :
Now I'll be adding employee id and department id in this table plus manager info etc..( info doesnt exist in employee table) , shall i use them as primary or create id column in this table ??
Thanks alot.Hi
I would use employe_id and department_id to define the PK. I see no reason for adding a meaningless key in such a case.
HTH
Chris Antognini
Troubleshooting Oracle Performance, Apress 2008
http://top.antognini.ch -
Hi,
Please explain how can I set a primary key ( with composite key, say fyear(7), voucher_no number(5),voucher_sub_no number(2)) for a new record in ADF using programming..
Thanks in advance
SureshFor this you have to use the freestAndIng method of the vo. There's you pass an NameAndValuePair list of the composite key to initialize the pk.
http://docs.oracle.com/cd/B14099_19/web.1012/b14022/oracle/jbo/RowIterator.html#createAndInitRow_oracle_jbo_AttributeList_
Should get you started.
Timo -
Let me know the standary primary key tables in standard table??
let me know the standary primary key tables in standard table??
Hi,
You can go and check the primary keys of a table in SE11 by entering the table name and pressing display.
You will get to see that there will be some fields with a tick mark in the primary key column.The fields which have such tick marks are the primary keys of that table.
As far as I know there is nothing called primary key tables.All tables have some fields as primary keys based upon which a record is uniquely defined in that table.
Hope it was useful.
Thanks,
Sandeep. -
Hi cant see the primary key column in master detail form
I have a master detail form .In the first master form i am unable to see the primary key
Now the form is built completley and i also will like to see the primary key column visible in master report
If i had set the primary key as rowid then i could have seen the primary key ..
Now i can see the pencil icon (The eidt row pencil icon) instead of the actual primary key column . .which is a number data..
I will like that too be visible ..Can any one guide what should i do for this..
ThanksHi Mat,,
I am using apex 4.2 db version 11g and in the first master page i had set the value of combo which is primary key column as text
But still iam not able to see the number ..Note if i recreate the form ..with rowid as primary key i am able to see the column since the pencil icon(edit icon) is on row id..
Currently All i see is the edit icon ..I need both the edit icon and also the number ..
Thanks -
Primary Key Issue With Creating Tables
Hi,
I have the following scripts to create my two tables in oracle 10g, i was wondering wether or not i had correctly set up my primary key or if there is a better way of doing it than the way i have.
Here are my two scripts for my tables:
CREATE TABLE CUSTOMER (
fname varchar2(15) NOT NULL,
lname varchar2(20) NOT NULL,
age varchar2(3) NOT NULL,
custAreaCode number(5) NOT NULL,
custNumber number(6) NOT NULL,
constraint cust_pk PRIMARY KEY (custAreaCode),
constraint cust_pk2 PRIMARY KEY (custNumber),
constraint age_chk CHECK (age >=18 AND age <150)
CREATE TABLE PHONECALL (
startDateTime smalldatetime NOT NULL,
custAreaCode number(5) NOT NULL, ---Reference PK From Customer Table
custNumber number(6) NOT NULL, ---Reference PK From Customer Table
dialledAreaCode number(5) NOT NULL,
dialledNumber number(6) NOT NULL,
crgPerMinute number number (3,1) NOT NULL,
endDateTime smalldatetime NOT NULL));
I am not sure if i have referenced the primary keys correctly in the PHONECALL table.
Thanks in advance :)Hi,
You want like this below ? I think that smalltime data type is not a valid type. Other thing, this is not a rule, but I advice you to put the primary key columns as the first columns of your table. One question: There is no PK on the phonecall table ?
SGMS@ORACLE10> create table customer (
2 custareacode number(5) not null,
3 custnumber number(6) not null,
4 fname varchar2(15) not null,
5 lname varchar2(20) not null,
6 age varchar2(3) not null,
7 constraint cust_pk primary key (custareacode),
8 constraint cust_uk unique (custnumber),
9 constraint age_chk check (age >=18 and age <150)
10 );
Table created.
SGMS@ORACLE10> create table phonecall (
2 custareacode number(5) not null constraint fk_phone_cusarecode_customer references customer,
3 custnumber number(6) not null constraint fk_phone_custnumber_customer references customer,
4 startdatetime date not null,
5 dialledareacode number(5) not null,
6 diallednumber number(6) not null,
7 crgperminute number (3,1) not null,
8 enddatetime date not null);
Table created.
SGMS@ORACLE10> select table_name,constraint_name,constraint_type from user_constraints
2 where table_name in ('CUSTOMER','PHONECALL') and constraint_type in ('P','U','R');
TABLE_NAME CONSTRAINT_NAME C
CUSTOMER CUST_PK P
CUSTOMER CUST_UK U
PHONECALL FK_PHONE_CUSARECODE_CUSTOMER R
PHONECALL FK_PHONE_CUSTNUMBER_CUSTOMER RCheers -
Update primary key/delete and reinsert records
Hi, I have been told to update some fields. The database is new to me, and now I see the field is the primary key (and it has child tables with that as foreign key). The person who told me isn't reachable until next week...
...wasn't a bad idea to update pk's? I see it's possible, deferring constraints...
update primary key
Re: Update Primary Key
...but it's better/safer the script deletes and later re-insert the records, right?
ThanksAlways is better be able to undo any change .
But ¡, why would you update pk's? it's possible but you colud find few problems like:
- many levels of foreign keys exists.
- not validate pk
Look at:
Re: Novalidate primary key -
Which one is better static inner classes or inheritance ?
Hi,
Consider following scenario,
Class A does some database related work and Class B,C,D has more specific tasks for specific databases. For now B,C,D has more static information like driver name etc.
1. I can either make class B,C,D as static inner classes OR
2. classes B,C,D can extend class A.
Case 1. makes it more flexible, if in future, B,C,D needs more than static methods.
Case 2. can avoid complexity and cost of instantiating differnt objects based on differnt scenarios.
Which approache is better in both ?
ThanksYes, I have seen abstract factory pattern , rather I have implemeted it at one place and in case 1. using abstract factory pattern is the way to initialize all classes.But my question is if I make all subclasses as a static inner classes, will it be better or efficient approach as compare to abstract factory pattern.Because Abstract factory patter adds more complications in code in turn it provides more flexibility.
-
Update enrolled table which has 6 composite primary key
Hi Everyone,
I am trying to update a grade column in table called enrolled which has 6 composite primary key column including SID, TERMYEAR, FACCODE, DEPCODE, COURSENO, SECNO and 2 extra column including GRADE, IDD all of them are of type VARCHAR2 as describe below:
To update this table I used the command below:
UPDATE enrolled
SET grade = :COURSE_BLOCK.GRADE_TEXT
WHERE IID = :GLOBAL.logUserid
AND SID = :COURSE_BLOCK.SID_TEXT
AND FACCODE = :COURSE_BLOCK.FACULTY_TEXT
AND DEPCODE = :COURSE_BLOCK.DEPARTMENT_TEXT
AND COURSENO = :COURSE_BLOCK.COURSE_TEXT
AND SECNO = :COURSE_BLOCK.SECTION_TEXT;
Note: the :GLOBAL.logUserid is a global variable that I assigned the user id when the user log on to the application.
When I run the application and fill out the form in order to update the table this doesn't update the table and if I use SQL*PLUS as well with the values that I use for the form to update the table I get message: o rows updated
Can Someone help please?Here is the solution.
The problem:
The problem was that the enrolled table was designed in a way that a student can enrolled in the lecture(LEC type column) and Laboratory(LAB type column). When a student is given a grade, it is given a grade for the course 100 (eg: 03-60-100) this course has a lecture and lab. this course belong to the faculty code 03(science) department 60 (computer Science) so when a student register to a course, will register to a lecture and a lab but he will receive a grade for the course 100 lec in this case Oracle couldn't update the table because there was two column with course 100 for that particular student Id
The solution:
There are many solution I believe but my quickest solution is when a student register to the course by default is given a grade 'I' means Incomplete then when the instructor add the grade, he can just update a grade from incomplete to the final grade (eg A) now the code will be to get only the course 100 that has grade and discard that doesn't have grade this means that I need only to make sure that the WHERE Clause grade is not null shown below.
UPDATE enrolled
SET grade = BLOCK_NAME.FIELD_NAME
WHERE grade IS NOY NULL
AND IID = BLOCK_NAME.FIELD
AND faccode = BLOCK_NAME.FIELD
AND depcode = BLOCK_NAME.FIELD
AND courseno= BLOCK_NAME.FIELD_NAME
NAD secno = BLOCK_NAME.FIELD_NAME
AND SID = BLOCK_NAME.FIELD_NAME -
In which case composite primary key allows NULL values in it
Hi to all
In what case composite primary key allows nulls in it.
Let us suppose, I created a composite primary key with 2 attributes.
CREATE TABLE sample
BNK_Id NUMBER(6),
BNK_Name VARCHAR2(20),
CONSTRAINT BNK_Id_Name_PK PRIMARY KEY(BNK_Id,BNK_Name)
When it allows null values in it.
thanks in advanceAre you sure that your instructor was not talking about unique keys? As Solomon said, a primary key always implies not null on all of the columns of the PK. However a unique key does not automatically imply not null, and can have nulls in a column as long as the values in the populated columns are unique.
SQL> create table test (
2 id number,
3 pid number,
4 descr varchar2(10));
Table created.
SQL> alter table test add constraint test_unq
2 unique (id, pid);
Table altered.
SQL> insert into test values (1, null, 'desc1');
1 row created.
SQL> insert into test values (2, null, 'desc2');
1 row created.
SQL> insert into test values (2, null, 'fail1');
insert into test values (2, null, 'fail1')
ERROR at line 1:
ORA-00001: unique constraint (OPS$ORACLE.TEST_UNQ) violatedJohn -
Error While Deploying A CMP Entity Bean With A Composite Primary Key
Hello all,
I have a problem deploying CMP Entity beans with composite primary keys. I have a CMP Entity Bean, which contains a composite primary key composed of two local stubs. If you know more about this please respond to my post on the EJB forum (subject: CMP Bean Local Stub as a Field of a Primary Key Class).
In the mean time, can you please tell me what following error message means and how to resolve it? From what I understand it might be a problem with Sun ONE AS 7, but I would like to make sure it's not me doing something wrong.
[05/Jan/2005:12:49:03] WARNING ( 1896): Validation error in bean CustomerSubscription: The type of non-static field customer of the key class
test.subscription.CustomerSubscriptionCMP_1530383317_JDOState$Oid must be primitive or must implement java.io.Serializable.
Update the type of the key class field.
Warning: All primary key columns in primary table CustomerSubscription of the bean corresponding to the generated class test.subscription.CustomerSubscriptionCMP_1530383317_JDOState must be mapped to key fields.
Map the following primary key columns to key fields: CustomerSubscription.CustomerEmail,CustomerSubscription.SubscriptionType. If you already have fields mapped to these columns, verify that they are key fields.Is it enough that a primary key class be serializable or all fields have to implement Serializable or be a primitive?
Please let me know if you need more information to answer my question.
Thanks.
NikolaHi Nikola,
There are several problems with your CMP bean.
1. Fields of a Primary Key Class must be a subset of CMP fields, so yes, they must be either a primitive or a Serializable type.
2. Sun Application Server does not support Primary Key fields of an arbitrary Serializable type (i.e. those that will be stored
as BLOB in the database), but only primitives, Java wrappers, String, and Date/Time types.
Do you try to use stubs instead of relationships or for some other reason?
If it's the former - look at the CMR fields.
If it's the latter, I suggest to store these fields as regular CMP fields and use some other value as the PK. If you prefer that
the CMP container generates the PK values, use the Unknown
PrimaryKey feature.
Regards,
-marina -
Querying on the basis of some attribute of composite primary key
Hello,
I am looking for suggestion about querying just on the basis of one attribute of the composite primary key.
TO exemplify,
I have a 6 attributes example A1,A2,A3,A4,A5,A6.
A1,A2 and A3 together, serve as composite primary key.Now,because of the need of the project,I want to do querying on the basis of any A1,A2 or A3.One way I could think of is to have secondary indices on each of A1,A2,A3.
Can some one explain me roughly how to go about it?
I am a new user of BerkeleyDB Java Edition,hence not sure what would be a good way to do it.I understand one way to do it,would be to keep A1,A2,A3 in the Key class and A1,A2,A3,A4,A5,A6 in the value class as well.Then create secondary indices on the A1,A2 and A3 individually.
Can someone suggest a more efficient way?
Thanks,
Will appreciate any suggestions.
PrateekExactly as you said. Create secondary indices on each attribute you want to index off of. I don't use the Java interface, but what you pretty much need to do is form your secondary key like so:
skey: pkey_individual_attribute
skeysize: pkey_individual_attribute_sizeHow to do this is documented in the BDB Java API docs:
For example:
class MyKeyCreator implements SecondaryKeyCreator {
public boolean createSecondaryKey(SecondaryDatabase secondary,
DatabaseEntry key,
DatabaseEntry data,
DatabaseEntry result)
throws DatabaseException {
// DO HERE: Extract the secondary key from the primary key and
// data, and set the secondary key into the result parameter.
return true;
SecondaryConfig secConfig = new SecondaryConfig();
secConfig.setKeyCreator(new MyKeyCreator());
// Now pass secConfig to Environment.openSecondaryDatabaseThe extractor function used to construct the secondary index is passed the primary key and primary data - therefore all the data is available to you with no need to duplicate the key within the data itself. While the standard example is to use some part of the primary data to form a secondary key - there's absolutely nothing against using only a part of the primary key to form a secondary key instead. The only thing you have to do is slice up said primary key and construct the "result" parameter to be a single attribute. The backend API already knows which composite key this secondary entry will be associated with and as such will implicitly form the data (or as you called it "value") section of the index (which will be the composite primary key passed to it).
The primary key/data should consist of the composite A1,A2,A3 with only A4,A5,A6 as data.
The secondary->get() call (within the Java API) takes a key and provides back the primary key and primary data (basically the same as the db->pget() call in the C API). Since you've already indexed individual attributes, based off of the composite key, into their own respective databases - you just query from one of your secondary indexes with whatever specific attribute as the key. You then use the filled in primary key and primary data to work off of. -
Null Field in Composite Primary Key
Can you have a column be part of a primary key and be nullable?
I have a table of three fields and I want them all to be part of a primary key, because I need all three columns to reference a unique row. However, one of the fields references a field in another table which can be null. Is there anyway I can achieve this?Any columns included in the primary key will be converted to not NULLable as necessary, so, no, you cannot have a NULLable column as part of a primary key.
You can, however, create a unique constraint that includes a NULLable column as part of the composite key.
Maybe you are looking for
-
Videos are not shown in folder
I have lumia 520 and I unable to understand that why my videos are not shown in video player list only SD card videos are shown and there is no option to select SD card or phone storage in video player just like as in mp3 music player . Is this probl
-
How do I get out of My Songs?
I've got GB on my iPad2 and was enjoying 'Curtain Call' in My Songs. I cannot seem to find a way back to the main part of GB whereby I can play smart instruments, etc. If I select instruments in My Songs it tells me I've got the maximum 8 selected. P
-
Financial Consolidation of multiple companies
Good Morning Expert! Just want to know if SAP B1 can handle financial consolidation and how to do it. Our requirement is to consolidate financials of 3 companies. Hope to hear from you soon Thanks. Sandra
-
I have a problem running programs from the DOS prompt. When I type the command javac Welcome.java, everything runs okay. I can view the file Welcome.class. But when I type the command java Welcome, I get the following error message: Exception in thre
-
What's meaning of assign source system in RSA1, BI content
by choosing BI self source system, SAP ERP source system, and other file systems.