Synthetic Primary Key (sequence number) vs natural primary key
I wonder if the sequence number is better than the primary key. I found a few tables only use the sequence number, some tables use the primary key only, and a few tables use both. Can someone give me a clue, one that I use when you create a table? TX in advance.Published by: 1B, 3 may 2012 21:07
I'm not sure I understand the question. I do not understand how it is either / or question.
Virtually every table must have a primary key. You can either use a primary key natural (something in the data that is unique and immutable) or you would use a synthetic primary key which is filled from a sequence. I strongly suggest using synthetic primary keys generated from a sequence for your primary key.
Justin
Tags: Database
Similar Questions
-
create table t (id int primary key, dt date, file_no int, batch_no int, data varchar2(5) ); insert into t values (1,trunc(sysdate),23,113,dbms_random.string('a',5)); -- 1.1.1 insert into t values (2,trunc(sysdate),23,345,dbms_random.string('a',5)); -- 1.2.1 insert into t values (3,trunc(sysdate),23,345,dbms_random.string('a',5)); -- 1.2.2 insert into t values (4,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.1 insert into t values (5,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.2 insert into t values (6,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.3 -- insert into t values (7,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.1 insert into t values (8,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.2 insert into t values (9,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.3 insert into t values (10,trunc(sysdate),24,222,dbms_random.string('a',5)); -- 2.2.1 insert into t values (11,trunc(sysdate),24,222,dbms_random.string('a',5)); -- 2.2.2 insert into t values (12,trunc(sysdate),24,111,dbms_random.string('a',5)); -- 2.3.1
Oracle 11.1
How can given this structure and data, I generate sequence at the end of each line numbers? Basically, the sequence number (x.y.z) is such that x (1.n) is awarded for each unique value in file_no. In each x, y (1.n) is assigned for each unique value of batch_no. Within each y, z (1.n) is assigned for all records of this batch. Sample data shows only dt but all sequences must reset and start over when dt changes.
I tried using row_number() over (partition by dt, file_no) and such but nothing quite gives me what I'm looking for.
Help? Thank you
Hello
HELEN wrote:
If you look at my CREATE TABLE, the ID column is a primary key and represents the order of the data in the file.
Done batch_no = 100 come before or after 101? Batch_no = 100 a ID so much until after the id for batch_no = 101.
Good point, but that won't happen because of the way the 'record' is generated. All batch_nos will be contiguous. So if batch_no 100 comes earlier in the file as 101, it should get some 2nd highest sequence number. Otherwise, lower. Basically, the 2nd part of the sequence must simialar logical number to the 3rd party (i.e. order by id) but that messes things. Still struggle with it. Any help appreciated.
I think I understand. You say that, because of the way that the ID is issued, it wouldn't matter if you used the highest id of the batch_no, or the lowest id, or the average, or if you chose one at random; you would get the correct order in all cases.
The following query uses the id low in the order file_no and batch_nos.
WITH got_min_ids AS
(
SELECT id, dt, file_no, batch_no, data
MIN (id) over (PARTITION BY dt
file_no
) AS min_id_file_no
MIN (id) over (PARTITION BY dt
file_no
batch_no
) AS min_id_batch_no
T
)
SELECT id, dt, file_no, batch_no, data
DENSE_RANK () OVER (PARTITION BY dt
ORDER BY min_id_file_no
)
|| '.'
|| DENSE_RANK () OVER (PARTITION BY dt
file_no
ORDER BY min_id_batch_no
)
|| '.'
|| ROW_NUMBER () OVER (PARTITION BY dt
file_no
batch_no
ORDER BY id
) AS seq
OF got_min_ids
ORDER BY dt, min_id_file_no, min_id_batch_no, id
;
The main request is in fact what I posted before, but instead of
"ORDER BY file_no" and "ORDER BY batch_no", she uses
"ORDER BY min_id_file_no" and "ORDER BY min_id_batch_no". These values are calculated in the subquery, got_min_ids.
Output (including the additional sample data I posted):
ID FILE_NO DT BATCH_NO SEQ DATA
---------- ----------- ---------- ---------- ----- ----------
1 23 25 April 2014 113 dXAad 1.1.1
2 345 23 25 April 2014 pumVG 1.2.1
3 345 23 25 April 2014 jLnbO 1.2.2
4 23 25 April 2014 543 xKhCL 1.3.1
5 23 25 April 2014 543 JQoWk 1.3.2
6 23 25 April 2014 543 YjJeC 1.3.3
7 24 25 April 2014 333 WjQNE 2.1.1
8 24 25 April 2014 333 ScWSL 2.1.2
9 24 25 April 2014 333 pXDSD 2.1.3
10 222 24 25 April 2014 OSajn 2.2.1
11 222 24 25 April 2014 QNpix 2.2.2
12 24 111 OwkjI 2.3.1 April 25, 2014
91 100 99 25 April 2014 sRWmT 3.1.1
93 100 99 25 April 2014 IAEFd 3.1.2
92 101 99 25 April odQxh 2014 3.2.1
I know you said that this situation is impossible (that is, if ID 91 and 93 have the same batch_no, then id 92 cannot have a different batch_no), but the application works even if this rule is broken.
-
How to find the sequence number of av
Downloaded eset uninstaller, but he asked for the sequence number
Hello Damien,.
If you don't know, go to the icon of the program or file name and right-click on it and select properties and in the window that opens, read on the top row of tabs up until you get to the Details tab, click to open the tab. The sequence number is given here?
If not, a freeware for you program called siw (System Information for Windows), download it here: http://download.cnet.com/SIW-Technician-s-Version/3000-2094_4-10915770.html . The application requires no installation, you simply double-click the name of the executable file, and the program opens to the software section. Scan down the list until you find the applications tab. Click to open your list and find details of eset and see if the sequence number is in the list.
One of these two approaches should solve the problem for you. Let me know how you fare.
Kind regards
BearPup
-
Hi all.
I really need your help on this:
(1) version: 11.2.0.1 EE / Windows.
(2) database does not start, don't get database.
Alert.log info:
Instance of stopped by USER, pid = 3652
2015-11-22 15:57:19.763000 - 04:30
I found this after using adrci:
2015-11-22 15:49:15.727
SESSION ID: (191.1) 2015-11-22 15:49:15.727
CUSTOMER ID :() 2015-11-22 15:49:15.727
NAME OF THE SERVICE :() 2015-11-22 15:49:15.727
MODULE NAME: (sqlplus.exe) 2015-11-22 15:49:15.727
ACTION NAME :() 2015-11-22 15:49:15.727
Informational message:
Control file 1 has seq 2713995, low 2713994 file # 0
Error: kccpb_sanity_check_2
Control file sequence number mismatch!
fhcsq: bhcsq 2713995: 2714016 cfn 0
2015-11-22 15:49:15.758
USER (ospid: 2504): put an end to the instance
Verification of MOS Note: 435436.1 I must:
(1) to restore a backup of a controlfile and recover
OR
(2) to recreate the controlfile
OR
(3) restore the backup data and recovery
It is a database, that I was not, up to now administer. But:
(1) I tried from the database with addressed controlfile (the one located in FRA). No luck. (Create pfile from spfile / startup pfile)
(2) the database is not mount / open. It hangs on the editing process. So I can not issue an alter database controlfile to trace.
It seems that my options are:
(1) manual creation of controlfile with open resetlogs option. This option is viable, but risky if we miss a datafile or something GOLD
(2) restoration of RMAN backup. The thing is that the most recent copy of automatic backup of controlfile is since a few days early (4 / 5 days).
I found this link: http://gavinsoorma.com/2009/07/rman-recovery-from-loss-of-all-control-files/
The procedure seems easy, but since this controlfile is not in the current SNA of database (data files, etc.). I'm not sure it if it would work.
So in short, I think I have an automatic backup controlfile and it's OK. but a little old. I can restore from this copy of CF?
Please I'm pressed real here, so help will be greatly appreciated!....
Thanks in advance!
Best regards, Luis...!
Hello
It seems that my options are:
(1) manual creation of controlfile with open resetlogs option. This option is viable, but risky if we miss a datafile or something GOLD
(2) restoration of RMAN backup. The thing is that the most recent copy of automatic backup of controlfile is since a few days early (4 / 5 days).
It seems that you have few options,
In my opinion, you should start with option 2), but you have logs archived redo and all and all the backups of catalog and perform a restore.
After, if not works, you must manually create the control files, but you are right, you must carefully on all the data files. Here a log generated in the last level 0 RMAN backup could help you, don't forget the newspaper are all entries of data for backup files.
I wish to have more ideas to help you, but I have no other.
I hope this helps.
Kind regards
Juan M
-
several insert using the same sequence number,
Hello
I need to use the same sequence number in several documents (insertion).
Is this possible and how?
Thank you
It depends on how you are doing multiple inserts. If you then run a bunch of single inserts something like:
dev1 > create table t (ID, descr varchar2 (10));
Table created.
dev1 > create sequence t_seq;
Order of creation.
dev1 > select double t_seq.nextval;
NEXTVAL
----------
1
dev1 > insert into values t (t_seq.currval, 'Rec 1');
1 line of creation.
dev1 > insert into values t (t_seq.currval, "Rec 2");
1 line of creation.
dev1 > insert into values t (t_seq.currval, 'Rec 3');
1 line of creation.
dev1 > insert into values t (t_seq.currval, 'Rec 4');
1 line of creation.
dev1 > insert into values t (t_seq.currval, 'Rec 5');
1 line of creation.
dev1 > select * from t;
ID DESCR
---------- ----------
1 rec 1
1 rec 2
1 rec 3
REC 2 4
REC 2 5
You can use a similar approach, if you select data from another table as long as you can make the selection sufficiently selective to retrieve only the lines you need.
John
-
Mr President.
How to set the default value of the attribute with a sequence number? Is it possible to add a string to seq.no. like abc0001?
Concerning
For the date, you can use groovy expression adf.currentDate to set the current date. reference http://adfgouravtkiet.blogspot.in/2012/11/how-to-set-default-values-for-entity.html
You already have ways to use the sequence.
How do you add a new value in the form. You're creating a new line of your page (user interface) and by engaging with validation operation? Unless you commit you will not be able to see anything in the table.
Thank you
-
Error with groovy expression of sequence number of EO attribute assignment?
Hello worldMy version of Jdeveloper is 11.1.2.3.0.
Starting from this post: https://tompeez.wordpress.com/category/adf/page/6/
I found to add a groovy expression for the sequence number to my attribute. I created a single sequence and added that the groovy expression to my attribute but got the error below:Utils > < buildFacesMessage > ADF: addition of the following JSF error message: failed to start, bc4j_model_TestEntityObject_Empno_null_gs.groovy: 1: lack of hook closing ' > ' for generic types.
solution: Please specify the missing support! @ line 1, column 12.
1 errororg.codehaus.groovy.control.MultipleCompilationErrorsException: failed to start, bc4j_model_TestEntityObject_Empno_null_gs.groovy: 1: lack of hook closing ' > ' for generic types.
solution: Please specify the missing support! @ line 1, column 12.
1 errorNote: groovy expresion used in my EO attribute is given below:
(new class < SPAN > 'skimlinks-fidget' = > oracle.jbo.server.SequenceImpl ("SampleSeq", adf.object.getDBTransaction ())) .getSequenceNumber </span >)also used:
(new class < SPAN > 'skimlinks-fidget' = > oracle.jbo.server.SequenceImpl ("SampleSeq", adf.object.getDBTransaction ()) .getSequenceNumber () </span >What can be the problem?
Please give me your valuable contributions...
Thank you.Sorry, somehow the code in the blog is messed up. Use
(new oracle.jbo.server.SequenceImpl ("SampleSeq", adf.object.getDBTransaction ()) .getSequenceNumber)
Where SampleSeq is the name of the sequence defined in the comic book.
Timo
-
How generations for db in the XSLT file sequence number
Hello gurus SOA,.
I have a requirement, please see below
I am using SOA 11.1.1.6
Insert a webservice to db, XSLT call, I have 10 items next to the source and 11 items next to the target.
- Source to target first 10 mappings are performed.
- Now the requirement is, for the 11th element target we must pass a sequence number to the database targeted, means-(sequence number must be generated for each execution of the XSLT execution)
How do the last point?
Can someone help me please
Hello
You can pass the sequence number in the 11th element to help. "
oraext:sequence-next-val("Sequence name as a string", "Datasource as a string") function.
Kind regards
Anshul
-
Error ORA-02287: sequence number not allowed here
Hello
I got an error ORA-02287: unauthorized here when you run sql statement insert below sequence number.
INSERT INTO SI_KEY_DBF
(M_IDENTITY, M_REF, M_GROUP, M_, M_TYPE, M_MULTIPLE, M_START, M_END, M_PREVIOUS, M_NEXT, M_INS_DATE, M_MOD_DATE,
M_INS_TIME, M_MOD_TIME, M_AMEND, M_LABEL, M_ENTITY, M_TRN_FAMILY, M_TRN_GROUP, M_TRN_TYPE, M_CURRENCY,
M_O_CUR, M_NOVO, M_CRDE, M_CODE, M_USER, M_VAL_STATUS, M_STL_METHOD, M_TRD_SECT, M_COMMENT, M_MARKET,
M_CLEARER, M_SI_TCI)
(SELECT M_IDENTITY, (SELECT SI_KEY_DBFS.nextval FROM dual), M_GROUP, m_, M_TYPE, M_MULTIPLE, NULL, NULL, M_PREVIOUS, M_NEXT, SYSDATE, SYSDATE,
To_Char(sysdate,'HH:mm:SS'), To_Char(SYSDATE,'HH:MM:SS'), 0, M_LABEL, M_ENTITY, M_TRN_FAMILY,.
M_TRN_GROUP, M_TRN_TYPE, M_CURRENCY, M_O_CUR, M_NOVO, M_CRDE, M_CODE, M_USER, M_VAL_STATUS,
M_STL_METHOD, M_TRD_SECT, M_COMMENT, M_MARKET, M_CLEARER, M_SI_TCI FROM SI_KEY_DBF WHERE M_REF IN
(M_REF SELECT TABLE #DATA #SITRN_DBF WHERE M_HLD_AC IN (SELECT IDXOAC FROM DDINDX)))
Can someone help me on how to solve this problem? Really appreciate your help. Thank you.>
(SELECT M_IDENTITY, (SELECT SI_KEY_DBFS.nextval FROM dual),
>
You already choose to get rid of the nested select statement and simply use the value(SELECT M_IDENTITY, SI_KEY_DBFS.nextval,
-
Wacky image sequence number - sparkles
Hi guys,.
I created a sequence of 2 simple images, I wanted to play at the top of my DPS document - but when I saw the article (on the desktop, iphone and ipad) the sequence of the image fails...
I took a quick screencap to show what is Im.
Sequence number of DPS images - YouTube
Any advice?
Effect of two images, I would use a slide show instead of a sequence of images. Not sure what is causing the flicker.
-
Generate a unique sequence number
Hello
I need generate a unique sequence number. I use Oracle 11.2, here are the details. The idSeq column is specific idType a unique interior. I don't want a sequence for each idType.
create table tb_test (idSeq number (5), number (5) idType, addr varchar2 (256));
insert into tb_test
(to select when idSeq is null then 1 another max (idSeq) + 1 end, 3, "Main street");
I have an ORA-00937: not a single-group function error, any suggestion?
Published by: 939569 on February 13, 2013 11:21Hello
939569 wrote:
HelloI need generate a unique sequence number.
Explain what you're trying to do, and why won't a sequence.
I use Oracle 11.2, here are the details. The idSeq column is specific idType a unique interior. I don't want a sequence for each idType.
create table tb_test (idSeq number (5), number (5) idType, addr varchar2 (256));
insert into tb_test
(to select when idSeq is null then 1 another max (idSeq) + 1 end, 3, "Main street");I have an ORA-00937: not an error of a single group group function,
Right. Given that the subquery uses an aggregate function (MAX), all in the SELECT clause must be an aggregate, a group of expression, a constant, or something that is entirely up to them. In this example, the CASE expression depends on idSeq, which is not an aggregate, not a group by expression (there is no GROUP BY clause) and not a constant.
In addition, the subquery must have a FROM clause. All queries and subqueries in Oracle require a FROM clause.
any suggestion?
Use a sequence. The numbers are not consecutive in each idType, but matter? Chances are, no matter what you do, you will not be able to maintain consecutive numbers within each idType anyway.
If you do not use a sequence, then you can try:
INSERT INTO tb_test (idSeq, idType, addr) SELECT 1 + NVL ( MAX (id_seq) , 0 ) , 3 , 'Main street; FROM tb_test WHERE idType = 3 ;
-
Hello
My oracle server is 11g in environment.and BECAUSE I have this is the sequence.
CREATE SEQUENCES "BUS_FILE_SEQ_NB."
MINVALUE MAXVALUE 1 999999999999999999999999999 INCREMENT OF 1 START WITH 36134
TO CACHE ALL NOCYCLE 20;
SELECT BUS_FILE_SEQ_NB. NEXTVAL FROM DUAL;
Due to this CAR, my sequence number is random, it is not in order as 1,2,3... (But its unique)
But I need to select records recent query using max (seq_column).
Someone you will suggest that how do to change the sequence to get arrested.
Thank you.Vanessa wrote:
HelloMy oracle server is 11g in environment.and BECAUSE I have this is the sequence.
CREATE SEQUENCES "BUS_FILE_SEQ_NB."
MINVALUE MAXVALUE 1 999999999999999999999999999 INCREMENT OF 1 START WITH 36134
TO CACHE ALL NOCYCLE 20;SELECT BUS_FILE_SEQ_NB. NEXTVAL FROM DUAL;
Due to this CAR, my sequence number is random, it is not in order as 1,2,3... (But its unique)
I don't believe you.
SEQUENCE values always increase; but the gaps that may exist.post SQL & results that show the value of the sequence is less than the previous.
>
>Vanessa wrote: but I need to select records recent query using max (seq_column).
Someone you will suggest that how do to change the sequence to get arrested.Thank you.
Hello
My oracle server is 11g in environment.and BECAUSE I have this is the sequence.
CREATE SEQUENCES "BUS_FILE_SEQ_NB."
MINVALUE MAXVALUE 1 999999999999999999999999999 INCREMENT OF 1 START WITH 36134
TO CACHE ALL NOCYCLE 20;SELECT BUS_FILE_SEQ_NB. NEXTVAL FROM DUAL;
Due to this CAR, my sequence number is random, it is not in order as 1,2,3... (But its unique)
But I need to select records recent query using max (seq_column).
Someone you will suggest that how do to change the sequence to get arrested.Thank you.
-
Insert/update of the XML help merge and to generate the sequence number
Hello
I'm working on Oracle 11 g.
I have a doubt with loading XML.
I get an xml and I need to insert or update data in a table. What I can accomplish by using the MERGE statement.
But there is a column in A table, I need to fill with a sequence number, based on the data sent in the xml file.
The XML does not send the data in this column.
And I have to make sure that sequence is created according to the order in which the records are present in xml.
For example the MERGER is insert five rows and update two lines and insert again 3 rows of xml in table A. The sequence number must be created in the same order for the column in the table.
Also for every new XML, the sequence starts with 1 and ends with the number of records in the xml file. I can't create a sequence and use the seq.nextval.
Please let me know, there is a way to achieve this.
Thank you!
Published by: 934451 on 8 August 2012 06:33
Published by: 934451 on 8 August 2012 06:50Hello
As a result of your previous thread: {: identifier of the thread = 2403469}
You can use the clause for ORDINALITE in XMLTable to generate the necessary sequence:
MERGE INTO target_table t USING ( SELECT x.seq_num, x.pk_id, x.col1, x.col2, ... FROM XMLTable( '/root/record' passing my_xml_doc columns seq_num FOR ORDINALITY , pk_id number path 'ID' , col1 varchar2(30) path 'COL1' , col2 varchar2(30) path 'COL2' , ... ) x ) src ON ( t.pk_id = src.pk_id ) WHEN MATCHED THEN UPDATE SET t.seq_num = src.seq_num , t.col1 = src.col1 , t.col2 = src.col2 , ... WHEN NOT MATCHED THEN INSERT (seq_num, pk_id, col1, col2, ...) VALUES (src.seq_num, src.pk_id, src.col1, src.col2, ...) ;
-
ORA-02287: sequence number not allowed here
< police = "Courier New" >
Hello
Why do I have this problem?
Insert an order tab2 select tab2_seq.nextval, eng_cat from (select distinct job_det eng_cat) by 2.
SQL > r
1 * insert into tab2_seq.nextval select eng_cat select (separate eng_cat tab2
Insert in tab2 select tab2_seq.nextval, eng_cat from (select distinct eng_cat from)
*
ERROR on line 1:
ORA-02287: sequence number not allowed here
Thank you and best regards,
Human
< / make >It's 'order of 2' which makes it fail. That makes no sense at all?
Just remove the order by clause, then it works ;-) -
How to run a same sequence number for the dynamic lines resulting
Hi friends,
I have a sequence and the trigger (which will trigger the id for each line insertion).
My scenario is, if I update more than 5 lines of a way of time, I need to define a same example (1) sequence number for all the 5 rows.
Next time, if I update another way for 5 rows, then I need to define a sequence of the same number (i.e.) 2 for the next 5 lines.
So my update will be dynamic (can be 2, 5, 10 rows at a time), but I need a same sequence number for one of the column for all of the lines that I'm updating the value.
Next time, if I update another series of lines means, then I need to put only the next sequence number (i.e) 2 (assume this sequence previously updated to the front of the set of rows is 1) for another set of lines.
As this sequence should update in a sequential manner for more than a set of rows in this column.
How friends.
example of
Brgds,id-----------------name 1-------------------A 1-------------------B 1-------------------C 1-------------------D 1-------------------E 2-------------------D 2-------------------E 2-------------------F 2-------------------G 3-------------------H 3-------------------I
MiniGenerate the value of the sequence and store it in a variable and use this variable in the UPDATE.
varSequence :=
.nextval; update set = varSequence where
Maybe you are looking for
-
My whatsapp does not work since yesterday. ! If it displays a blank screen of white that brings back me to my home screen after a few seconds. I don't get notifications whatsapp so. I tried the solutions found people who say started them to work afte
-
Hello community, I have a problem with my Portege Z (Windows 8.1). I use it in our society that is connected to our network via ethernet (dockingstation). When I use the "Logout" function to take ITTO our meeting room the following things occur: Only
-
In all recent versions of firefox (that I remember), I was able to type in any word in the address bar and it would take me to what was usually the first result of google, now it takes me just a google search.For example, I could type in "Wikipedia"
-
Hello I have a 4752-6838 and it will not now switch the "Press F2 to Bios setup" screen from the beginning. I disassembled the drive, try to boot from the CDRom, try to enter the bios and nothing. Does anyone have an idea of what's going on? Thank yo
-
my dvd burner is LG and its super multi and lightscribe