foreign key index
I read a book on the index, he saidYou should almost always index foreign keys because they are frequently used in joins. In addition, if you intend to delete or update unique or primary keys on the parent table, you should index the foreign keys to improve the locking of child records.
what I don't understand, I should create index on the foreign key in parent-child table or table column or both?Thank you
Hello
806540 wrote:
I read a book on the index, he saidYou should almost always index foreign keys because they are frequently used in joins. In addition, if you intend to delete or update unique or primary keys on the parent table, you should index the foreign keys to improve the locking of child records.
what I don't understand, I should create index on the foreign key in parent-child table or table column or both?
They mean that you need to create an index in the child table, that is the table that contains the foreign key constraint.
In order to have a foreign key constraint, it must have a primary key constraint, or a unique constraint on the column, or columns referenced in the parent table. Either type (primary key or unique) automatically creates an index, so there is nothing more you need to do in the parent table.
Tags: Database
Similar Questions
-
Difference between the foreign key index and secondary index
Hello
Suppose we have two primary databases,
Employee (id, company_id)
Company (id, name)
(where: the employee of the company is one to many, and I use the collections API)
If we want to perform a join between the employee and the company based on the ID of the company. I want to know the difference between the following two options:
1 - construction of a secondary index on the Employee (company_id). call this index index1. Then, we use the following code:
For each company c
index1.get (c.ID)
2 - construction of a foreign key on Employee (company_id) index where the database of foreign key was undertaken. call this index index2. Then, we use the following code:
For each company c
index2.get (c.ID)
I have two questions:
1 - What is the difference between these two options in terms of performance?
2. I know that one of the benefits of the foreign key are the application of integrity constraints (CASCADE, CANCEL, etc. to DELETE). That declare a foreign key to give me any advantage when I want to do a join? (for example a quick method, or a single statement to a join)
Thank you
Wait.It doesn't matter what the example, the only advantage of a foreign key index (above, the benefits of a secondary index) is that it imposes of foreign key constraints. There is no other advantage to a foreign key index.
-mark
-
can associate US foreign key index?
Hello
I've searched and can't find the answer to the foregoing;
I have a foreign key table constraint; I added an index on that column
However when I ask the all_constraints under index_name to this foreign constraint, there is nothing. only when I PK/UK I deal see index associated with them;
then oracle will still associate my index finger with the FK column forced? or I need excplicity pair with the foreign key column? If so, how?
THX
RgdsWhen you do "I added an index on that column;" you "associate explicitly" a column with an index.
You can check this withselect * from all_ind_columns
But there is no direct relationship between a FK constraint and index
-
To index foreign keys in 11 g?
Hello
We are on 11.2.0.2 on Solaris 10. A day back I had a mistake in our application due to a blockage. The trace file indicates that a single sql and the table. The table involved is a parent to a child table table and the foreign key of the child table is not indexed. What is the reason for the deadlock? Are foreign keys should be indexed in 11g also?
Note that the trace file has this statement: ("" the only resource deadlock: block the queue blocking himself, f 0 ' ").
It's the statement recorded in the trace file:
Here the col1 is a key to parent to an another table tab2 which has the same col1 column, but it is not indexed.delete from tab1 a where exists (select 1 from tab1 where col1 = a.col2 and col3 = :1) .
(I changed the names of the tables and columns to remove our specific details of the app).
Parts of the trace deadlock below:
Published by: orausern on Sep 17, 2012 05:03Trace file /oracle/diag/rdbms/wdb1/wdb1/trace/wdb1_ora_278.trc Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options ORACLE_HOME = /oracle/product/database/1120/db1 *** MODULE NAME:(JDBC Thin Client) 2012-09-14 16:36:08.865 *** ACTION NAME:() 2012-09-14 16:36:08.865 Single resource deadlock: blocking enqueue which blocks itself, f 0 Granted global enqueue 0xdb5663e8 ----------enqueue 0xdb5663e8------------------------ lock version : 30995 Owner inst : 1 grant_level : KJUSERCW req_level : KJUSERPW bast_level : KJUSERNL notify_func : (nil) resp : 0xdceae518 procp : 0xdb128fe8 pid : 27775 proc version : 505 oprocp : (nil) opid : 27775 group lock owner : 0xdc7979a0 possible pid : 27775 xid : 5F000-0001-00000E46 dd_time : 10.0 secs dd_count : 0 timeout : 60.0 secs On_timer_q? : Y On_dd_q? : Y lock_state : CONVERTING ast_flag : 0x0 Open Options : KJUSERDEADLOCK Convert options : KJUSERGETVALUE History : 0x4951495a Msg_Seq : 0x0 res_seq : 170 valblk : 0x00000000000000000000000000000000 . user session for deadlock lock 0xdb5663e8 sid: 468 ser: 14425 audsid: 82131588 user: 67/MIGRATION flags: (0x41) USR/- flags_idl: (0x1) BSY/-/-/-/-/- flags2: (0x40009) -/-/INC pid: 95 O/S info: user: grid, term: UNKNOWN, ospid: 27775 image: oracle@cdlt3f002db01 client details: O/S info: user: wasadmin, term: unknown, ospid: 1234 machine: cdldvjassvap050.nj.adp.com program: JDBC Thin Client application name: JDBC Thin Client, hash value=2546894660 current SQL: delete from tab1 a where exists (select 1 from tab1 where col1 = a.col2 and col3 = :1) Requesting global enqueue 0xdb9011b8 ----------enqueue 0xdb9011b8------------------------ lock version : 36319 Owner inst : 1 grant_level : KJUSERCW req_level : KJUSERPW bast_level : KJUSERNL notify_func : (nil) resp : 0xdceae518 procp : 0xdb1335c0 pid : 27778 proc version : 388 oprocp : (nil) opid : 27778 group lock owner : 0xdf6b9908 possible pid : 27778 xid : 51000-0001-000010E9 dd_time : 0.0 secs dd_count : 0 timeout : -910947.0 secs On_timer_q? : N On_dd_q? : N lock_state : CONVERTING ast_flag : 0x0 Open Options : KJUSERDEADLOCK Convert options : KJUSERGETVALUE History : 0x14951495 Msg_Seq : 0x0 res_seq : 170 valblk : 0x0000000000000000b81190db00000000 . user session for deadlock lock 0xdb9011b8 sid: 259 ser: 13977 audsid: 82131589 user: 67/scott flags: (0x41) USR/- flags_idl: (0x1) BSY/-/-/-/-/- flags2: (0x40009) -/-/INC pid: 81 O/S info: user: grid, term: UNKNOWN, ospid: 27778 image: oracle@cdlt3f002db01 client details: O/S info: user: wasadmin, term: unknown, ospid: 1234 machine: cdldvjassvap049.nj.adp.com program: JDBC Thin Client application name: JDBC Thin Client, hash value=2546894660 current SQL: delete from tab1 a where exists (select 1 from tab1 where col1 = a.col1 and col2 = :1) ----------resource 0xdceae518---------------------- resname : [0x159a5][0x0],[TM][ext 0x0,0x0] hash mask : x3 Local inst : 1 dir_inst : 2 master_inst : 2 hv idx : 121 hv last r.inc : 66 ..... ..... .....
Published by: orausern on Sep 17, 2012 05:04So I think you have your first suspect.
It is always helpful if you can come up with a script to reproduce the problem outside the application and then test that the foreign key indexing fixes the problem.
I hope that you would be able to lead to a test that relate to what your application is doing - you may have to really follow the sessions to discover all of the States involved.
But for something completely artificial:
SQL> create table parent 2 (col1 number not null primary key); Table created. SQL> create table child 2 (col1 number not null references parent(col1) on delete cascade 3 ,col2 number not null); Table created. SQL> insert into parent values(1); 1 row created. SQL> insert into parent values(2); 1 row created. SQL> insert into parent values(3); 1 row created. SQL> insert into child values(1,1); 1 row created. SQL> insert into child values(2,2); 1 row created. SQL> commit;
Session 1:
SQL> update child set col2=col2+1 where col1 = 1; 1 row updated. SQL>
Session 2:
SQL> update child set col2=col2+1 where col1 = 2; 1 row updated. SQL>
Session 1:
SQL> delete from parent where col1=1;
Session 2:
SQL> delete from parent where col1=2;
Which translates this in session 1:
delete from parent where col1=1 * ERROR at line 1: ORA-00060: deadlock detected while waiting for resource
And this in the blocking file (which is simpler than your own WFG):
DEADLOCK DETECTED ( ORA-00060 ) [Transaction Deadlock] The following deadlock is not an ORACLE error. It is a deadlock due to user error in the design of an application or from issuing incorrect ad-hoc SQL. The following information may aid in determining the deadlock: Deadlock graph: ---------Blocker(s)-------- ---------Waiter(s)--------- Resource Name process session holds waits process session holds waits TM-0007cb4a-00000000 34 642 SX SSX 35 706 SX SSX TM-0007cb4a-00000000 35 706 SX SSX 34 642 SX SSX session 642: DID 0001-0022-000003EC session 706: DID 0001-0023-0000031C session 706: DID 0001-0023-0000031C session 642: DID 0001-0022-000003EC Rows waited on: Session 642: no row Session 706: no row
And an index on (col1) child not cause this problem.
As I have said, but a little artificial...
Published by: Dom Brooks on 17 Sep 2012 14:18
-
Hi, we have a RAC Oracle 10 g 2 EE on SLES10.
I have tables with 300.000.000 of records. These paintings clues because it access it takes very very slow. I check what he need an index for each foreign key. I have a lot of tables and I'm looking for some tools or SQL or similar phrases that tell me, tables for each foreign key index. For example, I need to know what a lot of index left complete me the process and that it.
Table A
ID (PK)
B1_ID
B2_ID
C_ID
D_ID
...
...
(B1_ID, B2_ID) FK TO TABLE_B
(C_ID) FK IN TABLE C
(D_ID) FK TO TABLE_D
I create the index in table A, table B, but I don't have the index for the table C and table.
I have a lot of tables, with several foreign keys.
How can I find out what indexes that I need to create?
Thank you very much.You can also refer to http://blog.go-faster.co.uk/2007/10/tm-locking-checking-for-missing-indexes.html
HTH
Anand -
Is it still considered good practice to the foreign key indexes? I use 11g.
Prohan wrote:
Is it still considered good practice to the foreign key indexes? I use 11g.Yes, even for foreign keys, you can create indexes and as result you will get effective carry out the plan. It's good practice.
-
Find foreign keys are not indexed
Hello world
did anyone out there has a sql script that learns the foreign keys of a table are not indexed?
I was going to write a sql for it, but then I thought that someone somewhere must have written before...
DB: 10gR 1 and R2
ThksThis sql is courtesy of the asktom.oracle.com site.
To find the script you find «unindexed foreign keys»
When you run it, it will generate a report such as:
SQL > @unindex
STAT... TABLE_NAME COLUMNS COLUMNS
======== ============ =========== ========
APPLICATION_INSTANCES AI_APP_CODE
OK EMP DEPTNO DEPTNOThe * in the first line shows me that I have a foreign key that is not indexed in the APPLICATION_INSTANCES table. Ok in the second row shows me that I have an EMP table with a foreign key indexed.
column constraint_column format a20 word_wrapped
column index_column format a20 word_wrapped
column table table_name format a30 word_wrappedSelect decode (b.table_name, NULL, ' *', 'ok') status.
a.table_name, a.columns constraint_column, b.columns index_column
Of
(select table_name substr (a.table_name, 1, 30),
substr(a.constraint_name,1,30) constraint_name,
Max (decode (position, 1, substr(column_name,1,30), NULL)).
Max (decode (position, 2, ',': substr (column_name, 1, 30), null)).
Max (decode (position, 3, ',': substr (column_name, 1, 30), null)).
Max (decode (4 position ',': substr (column_name, 1, 30), null)).
Max (decode (position, 5, ',': substr (column_name, 1, 30), null)).
Max (decode (post, 6, ',': substr (column_name, 1, 30), null)).
Max (decode (position, 7, ',': substr (column_name, 1, 30), null)).
Max (decode (position, 8, ',': substr (column_name, 1, 30), null)).
Max (decode (position, 9, ',': substr (column_name, 1, 30), null)).
Max (decode (position, 10, ',': substr (column_name, 1, 30), null)).
Max (decode (position, 11, ',': substr (column_name, 1, 30), null)).
Max (decode (position, 12, ',': substr (column_name, 1, 30), null)).
Max (decode (position, 13, ',': substr (column_name, 1, 30), null)).
Max (decode (position, 14, ',': substr (column_name, 1, 30), null)).
Max (decode (position, 15', ': substr (column_name, 1, 30), null)).
Max (decode (position, 16, ',' | columns substr(column_name,1,30), null))
user_cons_columns a, b user_constraints
where a.constraint_name = b.constraint_name
and b.constraint_type = 'R '.
substr(a.table_name,1,30), substr(a.constraint_name,1,30)),
(select table_name, index_name substr (index_name, 1, 30) substr(table_name,1,30),
Max (decode (position_colonne, 1, substr(column_name,1,30), NULL)).
Max (decode (position_colonne, 2, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 3, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 4, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 5, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 6, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 7, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 8, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 9, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 10, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 11, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 12, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 13, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 14, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 15, ',': substr (column_name, 1, 30), null)).
Max (decode (position_colonne, 16, ',' | columns substr(column_name,1,30), null))
of user_ind_columns
Group of substr (table_name, 1, 30), substr (index_name, 1, 30)) b
where a.table_name = b.table_name (+)
and b.columns (+) like a.columns. '%'
/ -
Hello
I have a question about foreign key. When we create an index on a foreign key index name are displayed in the column index_name dba_constraints DD.
But the name of the index associated with the primary key is displayed.
Why so much?
Thanks in advance.Unique or Primary Key cannot guarantee the uniqueness of a column with an Index on that column. That's why Oracle will create an Index by default if there is no such thing as an index on that column all to utter those two constraints. If an index is always associated with these two constraints.
But no foreign key guarantees uniqueness on a column. And an Index on a foreign key is not required. So even if you create an index on a foreign key column that index is not associated with the foreign key.
-
I just read an article on the index.
Jonathan Lewis - during indexing
The author says that if you update the primary key or a unique key at the end of 'parent' of the referential integrity constraint Oracle locks the "child" table to find the rows of children committed and uncommitted if a suitable index does not exist. After that he says do not create indexes 'foreign key '. I mean, there is a contradiction. What do you think?
delete this thread!
-
How to find child every column foreign keys of tables without index {worm 10 g}
Hi Experts,
I have need of a query to find child all the foreign keys of table columns, which are not having an index on the foreign key column.
Try this.
SELECT T1. OWNER,
T1. CONSTRAINT_NAME,
T1. TABLE_NAME,
T2. COLUMN_NAME,
T1. CONSTRAINT_TYPE
OF ALL_CONSTRAINTS T1,.
ALL_CONS_COLUMNS T2
WHERE T1. CONSTRAINT_NAME = T2. CONSTRAINT_NAME
AND T1. TABLE_NAME = T2. TABLE-NAME
AND T1. OWNER = T2. OWNER
AND T1. CONSTRAINT_TYPE = 'R '.
AND T2. COLUMN_NAME NOT IN (SELECT COLUMN_NAME FROM ALL_IND_COLUMNS T WHERE TABLE_NAME = T1.) TABLE_NAME AND COLUMN_NAME = T2. COLUMN_NAME);
Post edited by: Parth272025
-
Strange problem deadlock (no foreign key not indexed)
Hello
We are on 11.2.0.2 on Linux. There is a blockage in our database (I first checked that no foreign key is not indexed). This impasse has this type of data in the alert file (after it cuts a lot). Can anyone suggest what might be the cause?
Published by: orausern on October 10, 2012 05:57--FROM Alert log: "Global Enqueue Services Deadlock detected. More info in file....trc" --below from trace file: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, Real Application Clusters, OLAP, Data Mining and Real Application Testing options ORACLE_HOME = /oracle/product/database/1120/db1 System name: Linux Node name: NODE1 Release: 2.6.32.59-0.3-default Version: #1 SMP 2012-04-27 11:14:44 +0200 Machine: x86_64 Instance name: db02 Redo thread mounted by this instance: 0 <none> Oracle process number: 12 Unix process pid: 17454, image: oracle@db01 (LMD0) *** 2012-09-16 00:54:00.094 *** SESSION ID:(181.1) 2012-09-16 00:54:00.094 *** CLIENT ID:() 2012-09-16 00:54:00.094 *** SERVICE NAME:() 2012-09-16 00:54:00.094 *** MODULE NAME:() 2012-09-16 00:54:00.094 *** ACTION NAME:() 2012-09-16 00:54:00.094 * Load Monitor used for high load check * Old Low - High Load Threshold Range = [0 - 0] * hlcpu 5 (kjihpc 5), slpct 90, llpct 75 * New Low - High Load Threshold Range = [30720 - 40960] *** 2012-09-16 00:54:02.690 KSXPCINI: kjxgnpub KSXP 2.2.0GESR000 13, 0 *** 2012-09-16 00:54:11.168 ftd (4) received from node 1 (84 5.0/0.0) all ftds received * kjxhvmaph: domain 0 valid = 1 according to instance 1 ftd (6) received from node 1 (84 7.0/0.0) all ftds received ftd (19) received from node 1 (84 20.0/0.0) all ftds received * Initialize deadlock detection * ftd (21) received from node 1 (84 22.0/0.0) all ftds received ftd (23) received from node 1 (84 22.0/0.0) all ftds received *** 2012-09-16 00:54:11.460 * kjxpnpgoh: PnP Go Ahead received from 1 (pnp inc 84) *** 2012-09-16 00:54:31.988 Begin DRM(399) (swin 1) - AFFINITY transfer pkey 4.1 to 2 oscan 1.1 kjiobjscn 1 ftd (30) received from node 1 (84 0.31/0.0) all ftds received ftd (33) received from node 1 (84 0.34/5.0) all ftds received ftd (35) received from node 1 (84 0.36/6.0) all ftds received ftd (37) received from node 1 (84 0.38/7.0) all ftds received 2012-09-16 00:54:32.061349 : * End DRM for pkey remastering request(s) (locally requested) *** 2012-09-16 00:55:02.914 2012-09-16 00:55:02.914301 : Setting 3-way CR grants to 1 global-lru off? 0 2012-09-16 03:00:44.727542 : Setting 3-way CR grants to 1 global-lru off? 0 *** 2012-09-16 03:04:25.696 Begin DRM(400) (swin 0) - AFFINITY transfer pkey 74335.0 to 2 oscan 0.0 kjiobjscn 1 ftd (30) received from node 1 (84 0.30/0.0) all ftds received * kjxftdn: break from kjxftdn, post lmon later ftd (37) received from node 1 (84 0.38/0.0) all ftds received ftd (30) received from node 1 (84 0.31/0.0) all ftds received ftd (33) received from node 1 (84 0.34/0.0) all ftds received ftd (35) received from node 1 (84 0.35/0.0) all ftds received * kjxftdn: break from kjxftdn, post lmon later ftd (37) received from node 1 (84 0.38/0.0) all ftds received ftd (30) received from node 1 (84 0.30/0.0) all ftds received (repeated such entry removed) * End DRM for pkey remastering request(s) (locally requested) *** 2012-09-17 07:20:51.111 Begin DRM(401) (swin 0) - AFFINITY transfer pkey 88491.0 to 2 oscan 0.0 kjiobjscn 1 ftd (30) received from node 1 (84 0.31/0.0) all ftds received ftd (30) received from node 1 (84 0.30/0.0) all ftds received * kjxftdn: break from kjxftdn, post lmon later ftd (33) received from node 1 (84 0.34/0.0) all ftds received ftd (35) received from node 1 (84 0.36/0.0) all ftds received * kjxftdn: break from kjxftdn, post lmon later 2012-09-17 07:20:51.407739 : * End DRM for pkey remastering request(s) (locally requested) *** 2012-09-17 22:04:10.873 Begin DRM(402) (swin 0) - AFFINITY transfer pkey 74331.0 to 2 oscan 0.0 kjiobjscn 1 *** 2012-09-17 22:04:11.001 ftd (30) received from node 1 (84 0.31/0.0) all ftds received ftd (33) received from node 1 (84 0.34/0.0) ftd (30) received from node 1 (84 0.30/0.0) all ftds received * kjxftdn: break from kjxftdn, post lmon later ftd (35) received from node 1 (84 0.36/0.0) all ftds received ftd (33) received from node 1 (84 0.33/0.0) all ftds received * kjxftdn: break from kjxftdn, post lmon later *** 2012-09-18 11:07:30.967 ftd (35) received from node 1 (84 0.36/0.0) all ftds received ftd (37) received from node 1 (84 0.38/0.0) all ftds received 2012-09-18 11:07:30.973676 : End DRM(405) for pkey transfer request(s) from 1 ENQUEUE DUMP REQUEST: from 1 spnum 12 on [0xf0008][0x24a0],[TX][ext 0x4,0x0] for reason 3 mtype 0 *** 2012-09-18 17:14:20.114 DUMP LOCAL BLOCKER/HOLDER: block level 3 res [0xf0008][0x24a0],[TX][ext 0x4,0x0] ----------resource 0xc2bc3f50---------------------- resname : [0xf0008][0x24a0],[TX][ext 0x4,0x0] hash mask : x3 Local inst : 2 dir_inst : 2 master_inst : 2 hv idx : 124 hv last r.inc : 84 current inc : 84 hv status : 0 hv master : 1 open options : dd grant_bits : KJUSERNL KJUSEREX grant mode : KJUSERNL KJUSERCR KJUSERCW KJUSERPR KJUSERPW KJUSEREX count : 1 0 0 0 0 1 val_state : KJUSERVS_NOVALUE valblk : 0x00000000000000000000000000000000 . access_inst : 2 vbreq_state : 0 state : x0 resp : 0xc2bc3f50 On Scan_q? : N Total accesses: 2652 Imm. accesses: 2516 Granted_locks : 1 Cvting_locks : 1 value_block: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 GRANTED_Q : lp 0xd0f7e510 gl KJUSEREX rp 0xc2bc3f50 [0xf0008][0x24a0],[TX][ext 0x4,0x0] master 2 gl owner 0xd5df5688 possible pid 19261 xid 53000-0002-00000286 bast 0 rseq 125 mseq 0 history 0x4977d495 open opt KJUSERDEADLOCK CONVERT_Q: lp 0xd0f7e6e0 gl KJUSERNL rl KJUSERPR rp 0xc2bc3f50 [0xf0008][0x24a0],[TX][ext 0x4,0x0] master 2 owner 1 bast 1 rseq 207 mseq 0x1 history 0x77d497ad convert opt KJUSERGETVALUE ----------enqueue 0xd0f7e510------------------------ lock version : 89 Owner inst : 2 grant_level : KJUSEREX req_level : KJUSEREX bast_level : KJUSERNL notify_func : (nil) resp : 0xc2bc3f50 procp : 0xdb10cc20 pid : 17454 proc version : 0 oprocp : (nil) opid : 17454 group lock owner : 0xd5df5688 possible pid : 19261 xid : 53000-0002-00000286 dd_time : 0.0 secs dd_count : 0 timeout : 0.0 secs On_timer_q? : N On_dd_q? : N lock_state : GRANTED ast_flag : 0x0 Open Options : KJUSERDEADLOCK Convert options : KJUSERNOQUEUE KJUSERNODEADLOCKWAIT History : 0x4977d495 Msg_Seq : 0x0 res_seq : 125 valblk : 0x00000000000000000000000000000000 . user session for deadlock lock 0xd0f7e510 sid: 290 ser: 713 audsid: 82787243 user: 64/SCOTT flags: (0x41) USR/- flags_idl: (0x1) BSY/-/-/-/-/- flags2: (0x40009) -/-/INC pid: 83 O/S info: user: grid, term: UNKNOWN, ospid: 19261 image: oracle@db1 client details: O/S info: user: wasadmin, term: unknown, ospid: 1234 machine: cdldvjassvap291 program: JDBC Thin Client application name: JDBC Thin Client, hash value=2546894660 current SQL: INSERT INTO tab1 SELECT x from tab2; DUMP LOCAL BLOCKER: initiate state dump for DEADLOCK possible owner[83.19261] on resource TX-000F0008-000024A0 *** 2012-09-18 17:14:20.115 Submitting asynchronized dump request [28]. summary=[ges process stack dump (kjdglblkrdm1)]. Global blockers dump start:--------------------------------- DUMP LOCAL BLOCKER/HOLDER: block level 3 res [0x150019][0x12b0a],[TX][ext 0x2,0x0] ----------resource 0xdcf6de80---------------------- resname : [0x150019][0x12b0a],[TX][ext 0x2,0x0] hash mask : x3 Local inst : 2 dir_inst : 1 master_inst : 1 hv idx : 119 hv last r.inc : 82 current inc : 84 hv status : 0 hv master : 0 open options : dd Held mode : KJUSERNL Cvt mode : KJUSERPR Next Cvt mode : KJUSERNL msg_seq : 0x1 res_seq : 32 grant_bits : KJUSERNL grant mode : KJUSERNL KJUSERCR KJUSERCW KJUSERPR KJUSERPW KJUSEREX count : 1 0 0 0 0 0 val_state : KJUSERVS_NOVALUE valblk : 0xd0f5415aff7f00000000000000000000 .AZ access_inst : 1 vbreq_state : 0 state : x8 resp : 0xdcf6de80 On Scan_q? : N Total accesses: 3472 Imm. accesses: 1369 Granted_locks : 0 Cvting_locks : 1 value_block: d0 f5 41 5a ff 7f 00 00 00 00 00 00 00 00 00 00 GRANTED_Q : CONVERT_Q: lp 0xdb976808 gl KJUSERNL rl KJUSERPR rp 0xdcf6de80 [0x150019][0x12b0a],[TX][ext 0x2,0x0] master 1 gl owner 0xdc688bc0 possible pid 19261 xid 53000-0002-00000286 bast 0 rseq 32 mseq 0 history 0x495149da convert opt KJUSERGETVALUE DUMP LOCAL BLOCKER/HOLDER: block level 3 res [0xf0008][0x24a0],[TX][ext 0x4,0x0] ----------resource 0xc2bc3f50---------------------- resname : [0xf0008][0x24a0],[TX][ext 0x4,0x0] hash mask : x3 Local inst : 2 dir_inst : 2 master_inst : 2 hv idx : 124 hv last r.inc : 84 current inc : 84 hv status : 0 hv master : 1 open options : dd grant_bits : KJUSERNL KJUSEREX grant mode : KJUSERNL KJUSERCR KJUSERCW KJUSERPR KJUSERPW KJUSEREX count : 1 0 0 0 0 1 val_state : KJUSERVS_NOVALUE valblk : 0xd0f5415aff7f00000000000000000000 .AZ access_inst : 2 vbreq_state : 0 state : x0 resp : 0xc2bc3f50 On Scan_q? : N Total accesses: 2654 Imm. accesses: 2517 Granted_locks : 1 Cvting_locks : 1 value_block: d0 f5 41 5a ff 7f 00 00 00 00 00 00 00 00 00 00 GRANTED_Q : lp 0xd0f7e510 gl KJUSEREX rp 0xc2bc3f50 [0xf0008][0x24a0],[TX][ext 0x4,0x0] master 2 gl owner 0xd5df5688 possible pid 19261 xid 53000-0002-00000286 bast 0 rseq 125 mseq 0 history 0x4977d495 open opt KJUSERDEADLOCK CONVERT_Q: lp 0xd0f7e6e0 gl KJUSERNL rl KJUSERPR rp 0xc2bc3f50 [0xf0008][0x24a0],[TX][ext 0x4,0x0] master 2 owner 1 bast 1 rseq 207 mseq 0x1 history 0x77d497ad convert opt KJUSERGETVALUE ----------enqueue 0xd0f7e510------------------------ lock version : 89 Owner inst : 2 grant_level : KJUSEREX req_level : KJUSEREX bast_level : KJUSERNL notify_func : (nil) resp : 0xc2bc3f50 procp : 0xdb10cc20 pid : 17454 proc version : 0 oprocp : (nil) opid : 17454 group lock owner : 0xd5df5688 possible pid : 19261 xid : 53000-0002-00000286 dd_time : 0.0 secs dd_count : 0 timeout : 0.0 secs On_timer_q? : N On_dd_q? : N lock_state : GRANTED ast_flag : 0x0 Open Options : KJUSERDEADLOCK Convert options : KJUSERNOQUEUE KJUSERNODEADLOCKWAIT History : 0x4977d495 Msg_Seq : 0x0 res_seq : 125 valblk : 0x00000000000000003100050200000000 .1 user session for deadlock lock 0xd0f7e510 sid: 290 ser: 713 audsid: 82787243 user: 64/SCOTT flags: (0x41) USR/- flags_idl: (0x1) BSY/-/-/-/-/- flags2: (0x40009) -/-/INC pid: 83 O/S info: user: grid, term: UNKNOWN, ospid: 19261 image: oracle@db1 client details: O/S info: user: wasadmin, term: unknown, ospid: 1234 machine: cdldvjassvap291 program: JDBC Thin Client application name: JDBC Thin Client, hash value=2546894660 current SQL: INSERT INTO tab1 SELECT x from tab2; (made up ) DUMP LOCAL BLOCKER: initiate state dump for DEADLOCK possible owner[83.19261] on resource TX-000F0008-000024A0 *** 2012-09-18 17:14:20.116 Submitting asynchronized dump request [28]. summary=[ges process stack dump (kjdglblkrdm1)]. Global blockers dump end:----------------------------------- Global Wait-For-Graph(WFG) at ddTS[0.1] : BLOCKED 0xdb976808 3 wq 2 cvtops x1 TX 0x150019.0x12b0a(ext 0x2,0x0)[53000-0002-00000286] inst 2 BLOCKER 0xcc55d558 3 wq 1 cvtops x28 TX 0x150019.0x12b0a(ext 0x2,0x0)[4C000-0001-0000014C] inst 1 BLOCKED 0xdb7dcfc8 3 wq 2 cvtops x1 TX 0xf0008.0x24a0(ext 0x4,0x0)[4C000-0001-0000014C] inst 1 BLOCKER 0xd0f7e510 3 wq 1 cvtops x28 TX 0xf0008.0x24a0(ext 0x4,0x0)[53000-0002-00000286] inst 2 *** 2012-09-18 17:14:20.687 * Cancel deadlock victim lockp 0xdb976808 *** 2012-09-18 17:14:25.028 ENQUEUE DUMP REQUEST: from 1 spnum 12 on [0x1a0006][0x2b6e],[TX][ext 0x4,0x0] for reason 3 mtype 0 DUMP LOCAL BLOCKER/HOLDER: block level 3 res [0x1a0006][0x2b6e],[TX][ext 0x4,0x0] ----------resource 0xde49c768---------------------- resname : [0x1a0006][0x2b6e],[TX][ext 0x4,0x0] hash mask : x3 Local inst : 2 dir_inst : 2 master_inst : 2 hv idx : 72 hv last r.inc : 84 current inc : 84 hv status : 0 hv master : 1 open options : dd grant_bits : KJUSERNL KJUSEREX grant mode : KJUSERNL KJUSERCR KJUSERCW KJUSERPR KJUSERPW KJUSEREX count : 1 0 0 0 0 1 val_state : KJUSERVS_NOVALUE valblk : 0x00000000000000000000000000000000 . access_inst : 2 vbreq_state : 0 state : x0 resp : 0xde49c768 On Scan_q? : N Total accesses: 1823 Imm. accesses: 1789 Granted_locks : 1 Cvting_locks : 1 value_block: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 GRANTED_Q : lp 0xdb40f4a0 gl KJUSEREX rp 0xde49c768 [0x1a0006][0x2b6e],[TX][ext 0x4,0x0] master 2 gl owner 0xd7f08fa8 possible pid 19228 xid 46000-0002-000004A4 bast 0 rseq 32 mseq 0 history 0x4977d495 open opt KJUSERDEADLOCK CONVERT_Q: lp 0xdb414320 gl KJUSERNL rl KJUSERPR rp 0xde49c768 [0x1a0006][0x2b6e],[TX][ext 0x4,0x0] master 2 owner 1 bast 1 rseq 190 mseq 0x1 history 0x77d497ad convert opt KJUSERGETVALUE ----------enqueue 0xdb40f4a0------------------------ lock version : 129 Owner inst : 2 grant_level : KJUSEREX req_level : KJUSEREX bast_level : KJUSERNL notify_func : (nil) resp : 0xde49c768 procp : 0xdb10cc20 pid : 17454 proc version : 0 oprocp : (nil) opid : 17454 group lock owner : 0xd7f08fa8 possible pid : 19228 xid : 46000-0002-000004A4 dd_time : 0.0 secs dd_count : 0 timeout : 0.0 secs On_timer_q? : N On_dd_q? : N lock_state : GRANTED ast_flag : 0x0 Open Options : KJUSERDEADLOCK Convert options : KJUSERNOQUEUE KJUSERNODEADLOCKWAIT History : 0x4977d495 Msg_Seq : 0x0 res_seq : 32 valblk : 0x00000000000000000000000000000000 . user session for deadlock lock 0xdb40f4a0 sid: 94 ser: 2065 audsid: 82787238 user: 64/SCOTT flags: (0x41) USR/- flags_idl: (0x1) BSY/-/-/-/-/- flags2: (0x40009) -/-/INC pid: 70 O/S info: user: grid, term: UNKNOWN, ospid: 19228 image: oracle@db1 client details: O/S info: user: wasadmin, term: unknown, ospid: 1234 machine: cdldvjassvap291 program: JDBC Thin Client application name: JDBC Thin Client, hash value=2546894660 current SQL: INSERT INTO tab1 SELECT x from tab2; (made up) DUMP LOCAL BLOCKER: initiate state dump for DEADLOCK possible owner[70.19228] on resource TX-001A0006-00002B6E *** 2012-09-18 17:14:25.029 Submitting asynchronized dump request [28]. summary=[ges process stack dump (kjdglblkrdm1)]. Global blockers dump start:--------------------------------- DUMP LOCAL BLOCKER/HOLDER: block level 3 res [0x160016][0x9249],[TX][ext 0x2,0x0] ----------resource 0xdb2d6758---------------------- resname : [0x160016][0x9249],[TX][ext 0x2,0x0] hash mask : x3 Local inst : 2 dir_inst : 1 master_inst : 1 hv idx : 51 hv last r.inc : 82 current inc : 84 hv status : 0 hv master : 0 open options : dd Held mode : KJUSERNL Cvt mode : KJUSERPR Next Cvt mode : KJUSERNL msg_seq : 0x1 res_seq : 49 grant_bits : KJUSERNL grant mode : KJUSERNL KJUSERCR KJUSERCW KJUSERPR KJUSERPW KJUSEREX count : 1 0 0 0 0 0 val_state : KJUSERVS_NOVALUE valblk : 0xd0f5415aff7f00000000000000000000 .AZ access_inst : 1 vbreq_state : 0 state : x8 resp : 0xdb2d6758 On Scan_q? : N Total accesses: 1620 Imm. accesses: 1442 Granted_locks : 0 Cvting_locks : 1 value_block: d0 f5 41 5a ff 7f 00 00 00 00 00 00 00 00 00 00 GRANTED_Q : CONVERT_Q: lp 0xdb682d78 gl KJUSERNL rl KJUSERPR rp 0xdb2d6758 [0x160016][0x9249],[TX][ext 0x2,0x0] master 1 gl owner 0xdc568020 possible pid 19228 xid 46000-0002-000004A4 bast 0 rseq 49 mseq 0 history 0x495149da convert opt KJUSERGETVALUE DUMP LOCAL BLOCKER/HOLDER: block level 3 res [0x1a0006][0x2b6e],[TX][ext 0x4,0x0] ----------resource 0xde49c768---------------------- resname : [0x1a0006][0x2b6e],[TX][ext 0x4,0x0] hash mask : x3 Local inst : 2 dir_inst : 2 master_inst : 2 hv idx : 72 hv last r.inc : 84 current inc : 84 hv status : 0 hv master : 1 open options : dd grant_bits : KJUSERNL KJUSEREX grant mode : KJUSERNL KJUSERCR KJUSERCW KJUSERPR KJUSERPW KJUSEREX count : 1 0 0 0 0 1 val_state : KJUSERVS_NOVALUE valblk : 0xd0f5415aff7f00000000000000000000 .AZ access_inst : 2 vbreq_state : 0 state : x0 resp : 0xde49c768 On Scan_q? : N Total accesses: 1825 Imm. accesses: 1790 Granted_locks : 1 Cvting_locks : 1 value_block: d0 f5 41 5a ff 7f 00 00 00 00 00 00 00 00 00 00 GRANTED_Q : lp 0xdb40f4a0 gl KJUSEREX rp 0xde49c768 [0x1a0006][0x2b6e],[TX][ext 0x4,0x0] master 2 gl owner 0xd7f08fa8 possible pid 19228 xid 46000-0002-000004A4 bast 0 rseq 32 mseq 0 history 0x4977d495 open opt KJUSERDEADLOCK CONVERT_Q: lp 0xdb414320 gl KJUSERNL rl KJUSERPR rp 0xde49c768 [0x1a0006][0x2b6e],[TX][ext 0x4,0x0] master 2 owner 1 bast 1 rseq 190 mseq 0x1 history 0x77d497ad convert opt KJUSERGETVALUE ----------enqueue 0xdb40f4a0------------------------ lock version : 129 Owner inst : 2 grant_level : KJUSEREX req_level : KJUSEREX bast_level : KJUSERNL notify_func : (nil) resp : 0xde49c768 procp : 0xdb10cc20 pid : 17454 proc version : 0 oprocp : (nil) opid : 17454 group lock owner : 0xd7f08fa8 possible pid : 19228 xid : 46000-0002-000004A4 dd_time : 0.0 secs dd_count : 0 timeout : 0.0 secs On_timer_q? : N On_dd_q? : N lock_state : GRANTED ast_flag : 0x0 Open Options : KJUSERDEADLOCK Convert options : KJUSERNOQUEUE KJUSERNODEADLOCKWAIT History : 0x4977d495 Msg_Seq : 0x0 res_seq : 32 valblk : 0x00000000000000003100050200000000 .1 user session for deadlock lock 0xdb40f4a0 sid: 94 ser: 2065 audsid: 82787238 user: 64/SCOTT flags: (0x41) USR/- flags_idl: (0x1) BSY/-/-/-/-/- flags2: (0x40009) -/-/INC pid: 70 O/S info: user: grid, term: UNKNOWN, ospid: 19228 image: oracle@db1 client details: O/S info: user: wasadmin, term: unknown, ospid: 1234 machine: cdldvjassvap291 program: JDBC Thin Client application name: JDBC Thin Client, hash value=2546894660 current SQL: INSERT INTO tab1 SELECT x from tab2;(made up) DUMP LOCAL BLOCKER: initiate state dump for DEADLOCK possible owner[70.19228] on resource TX-001A0006-00002B6E *** 2012-09-18 17:14:25.030 Submitting asynchronized dump request [28]. summary=[ges process stack dump (kjdglblkrdm1)]. Global blockers dump end:----------------------------------- Global Wait-For-Graph(WFG) at ddTS[0.2] : BLOCKED 0xdb682d78 3 wq 2 cvtops x1 TX 0x160016.0x9249(ext 0x2,0x0)[46000-0002-000004A4] inst 2 BLOCKER 0xcefeaf70 3 wq 1 cvtops x28 TX 0x160016.0x9249(ext 0x2,0x0)[54000-0001-000000A9] inst 1 BLOCKED 0xdb9b6380 3 wq 2 cvtops x1 TX 0x1a0006.0x2b6e(ext 0x4,0x0)[54000-0001-000000A9] inst 1 BLOCKER 0xdb40f4a0 3 wq 1 cvtops x28 TX 0x1a0006.0x2b6e(ext 0x4,0x0)[46000-0002-000004A4] inst 2 *** 2012-09-18 17:14:25.667 * Cancel deadlock victim lockp 0xdb682d78 *** 2012-09-18 18:09:23.508 Begin DRM(406) (swin 0) - AFFINITY transfer pkey 88431.0 to 2 oscan 0.0 kjiobjscn 1 ftd (30) received from node 1 (84 0.30/0.0) all ftds received * kjxftdn: break from kjxftdn, post lmon later ftd (33) received from node 1 (84 0.34/0.0) all ftds received ftd (35) received from node 1 (84 0.36/0.0) all ftds received ftd (37) received from node 1 (84 0.38/0.0) all ftds received ftd (30) received from node 1 (84 0.31/0.0) all ftds received ftd (33) received from node 1 (84 0.34/0.0) all ftds received ftd (35) received from node 1 (84 0.36/0.0) all ftds received ftd (37) received from node 1 (84 0.38/0.0) all ftds received ftd (30) received from node 1 (84 0.30/0.0) all ftds received
Published by: orausern on October 10, 2012 05:58Let them show you some code. Do not believe anything they said your question don't tell not only
-
Creation of primary keys, foreign keys and indexes
Hello
I created 60 new tables based on 60 existing tables.
The 60 current tables are named FY11_ACC1, FY11_ACC2, FY11_SALES1, FY11_SALES2..., but all of the 60 tables start with FY11. I created the same structured tables but with names like FY12_ACC1, FY12_ACC2, FY12_SALES1, FY12_SALES2 FY12...
I used the below SQL and generated SQL code.
Select 'create table ' | Replace (table_name, 11, 12).
' in select * from '. table_name | "where 1 = 0'.
from user_tables;
But this did not generate the PRIMARY KEYS, FOREIGN KEYS and INDEXES. How can I automatically or with similar like SQL above? _
Thanks for your time and your help.
How can I create primary keys, foreign keys and indexes for allssk1974 wrote:
Can you please provide me with more information or examples.Something like:
SET SERVEROUTPUT ON FORMAT WORD DECLARE h NUMBER; th NUMBER; ddl CLOB; BEGIN h := DBMS_METADATA.OPEN('TABLE_EXPORT'); DBMS_METADATA.SET_FILTER(h,'SCHEMA','SCOTT'); DBMS_METADATA.SET_FILTER(h,'NAME','DEPT'); DBMS_METADATA.SET_FILTER(h,'EXCLUDE_PATH_EXPR','=''TABLE_DATA'''); DBMS_METADATA.SET_FILTER(h,'EXCLUDE_PATH_EXPR','=''STATISTICS'''); th := DBMS_METADATA.ADD_TRANSFORM(h,'DDL'); DBMS_METADATA.SET_TRANSFORM_PARAM(th,'PRETTY',false); DBMS_METADATA.SET_TRANSFORM_PARAM(th,'SQLTERMINATOR',true); LOOP ddl := DBMS_METADATA.FETCH_CLOB(h); EXIT WHEN DDL IS NULL; DBMS_OUTPUT.PUT_LINE (ddl); END LOOP; DBMS_METADATA.CLOSE(h); END; / CREATE TABLE "SCOTT"."DEPT" ("DEPTNO" NUMBER(2,0), "DNAME" VARCHAR2(14), "LOC" VARCHAR2(13), CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" ENABLE) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" ; CREATE UNIQUE INDEX "SCOTT"."PK_DEPT" ON "SCOTT"."DEPT" ("DEPTNO") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" ; ALTER TABLE "SCOTT"."DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" ENABLE; PL/SQL procedure successfully completed. SQL>
SY.
Published by: Solomon Yakobson January 5, 2012 16:22
-
How to associate an index with a foreign key constraint
I understand how to associate a primary key constraint or a Unique key constraint index...
Yet I don't see how to associate the index of a foreign key constraint. Is this possible?
Thank you
Bob LarsenHi Bob,
In Data Modeler, physical model for Oracle primary and unique keys dialog boxes offer an Index field using, which is used to generate the 'using_index_clause' in the DDL for primary and Unique key constraints.
However the Oracle Database DDL does not have the "using_index_clause" for Foreign Key constraints, thus Data Modeler does not provide this feature for foreign keys.So, you will need to create a separate Index that uses the same columns as the foreign key (using the index page of the table properties dialog box in the relational model).
David
-
I have a large table which basically consists of the foreign keys to other tables (see below). Initially, I decided to create indexes of separate table for each of my foreign key columns. Because of the amount of records in the table, my index tablespace is taking up more data tablespace. What is the recommendation to add indexes for foreign key columns in a table?
Thank you
CREATE TABLE STU_ENROLLMENT
(PK_ID VARCHAR2 (32), sys_guid() by default)
CONSTRAINT pk_stu_enrollment
KEY ELEMENTARY SCHOOL
With the HELP of INDEX TABLESPACE sis_express_index
STORAGE (4096 INITIAL
NEXT 4096
PCTINCREASE 0),.
Fk_stu_enrollment_stu_school FK_STU_SCHOOL VARCHAR2 (32) CONSTRAINT
REFERENCES
stu_school (PK_ID)
ON DELETE CASCADE,
Fk_stu_enrollment_schl_cal FK_SCHOOL_CALENDAR VARCHAR2 (32) CONSTRAINT
REFERENCES
school_calendar (PK_ID)
ON DELETE CASCADE,
Fk_stu_enrollment_pcc_code FK_PCC_CODE VARCHAR2 (32) CONSTRAINT
REFERENCES
pcc_code (PK_ID)
ON DELETE CASCADE,
Fk_stu_enrollment_grade_level FK_GRADE_LEVEL VARCHAR2 (32) CONSTRAINT
REFERENCES
grade_level (PK_ID)
REMOVE THE NULL VALUE,
PCC_NOTES VARCHAR2 (1000)
CREATE INDEX STU_ENROLLMENT_I2 ON STU_ENROLLMENT (FK_SCHOOL_CALENDAR)
TABLESPACE sis_express_index
STORAGE (4096 INITIAL
NEXT 4096
PCTINCREASE 0);
CREATE INDEX STU_ENROLLMENT_I3 ON STU_ENROLLMENT (FK_PCC_CODE)
TABLESPACE sis_express_index
STORAGE (4096 INITIAL
NEXT 4096
PCTINCREASE 0);
CREATE INDEX STU_ENROLLMENT_I4 ON STU_ENROLLMENT (FK_GRADE_LEVEL)
TABLESPACE sis_express_index
STORAGE (4096 INITIAL
NEXT 4096
PCTINCREASE 0);
CREATE INDEX STU_ENROLLMENT_I5 ON STU_ENROLLMENT (FK_VOTECH)
TABLESPACE sis_express_index
STORAGE (4096 INITIAL
NEXT 4096
PCTINCREASE 0);
CREATE INDEX STU_ENROLLMENT_I6 ON STU_ENROLLMENT (FK_SPECIAL_ED)
TABLESPACE sis_express_index
STORAGE (4096 INITIAL
NEXT 4096
PCTINCREASE 0);
CREATE INDEX STU_ENROLLMENT_I7 ON STU_ENROLLMENT (FK_TUITION_CODE)
TABLESPACE sis_express_index
STORAGE (4096 INITIAL
NEXT 4096
PCTINCREASE 0);Salvation;
Please see entery Tom site
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:292016138754Respect of
HELIOS -
Index and foreign key referring to itself
Hello!
I'm working on an application that uses a basket stored in a database. The shopping cart uses two tables:
BASKET: Contains the common information for a shopping cart: the user is logged in etc.
-Primary key: CART_ID
CART_ROW: A line in the shopping cart, for example a new product to buy.
-Primary key: ROW_ID
-Foreign key: CART_ROW. References CART_ID CART. CART_ID
On the code lines in the basket are taken by cart, as is modeled by the foreign key. There is a relationship, that we use in the code, but which is not modelled by a foreign key in the database. A line can be dependent on another line, which makes the other row a parent.
CART_ROW has a PARENT_ID column that refers to CART_ROW. ROW_ID.
Would you add a foreign key to PARENT_ID? Or are there issues to consider when it is a foreign key to the same table?
Some time ago, we added the index, both ROW_ID PARENT_ID. The index on PARENT_ID could have harmful, since there is no foreign key?
Best regards!user9005175 wrote:
Hello!I'm working on an application that uses a basket stored in a database. The shopping cart uses two tables:
BASKET: Contains the common information for a shopping cart: the user is logged in etc.
-Primary key: CART_IDCART_ROW: A line in the shopping cart, for example a new product to buy.
-Primary key: ROW_ID
-Foreign key: CART_ROW. References CART_ID CART. CART_IDOn the code lines in the basket are taken by cart, as is modeled by the foreign key. There is a relationship, that we use in the code, but which is not modelled by a foreign key in the database. A line can be dependent on another line, which makes the other row a parent.
CART_ROW has a PARENT_ID column that refers to CART_ROW. ROW_ID.
Would you add a foreign key to PARENT_ID? Or are there issues to consider when it is a foreign key to the same table?I suggest to add the foreign key, it will not harm performance (except during an insert when there is validation of the foreign key). But it would avoid users to insert bad data / corrupted by code or directly on loggin in the database.
Some time ago, we added the index, both ROW_ID PARENT_ID. The index on PARENT_ID could have harmful, since there is no foreign key?
Index on parent_id would be dangerous if you do not use index after it is created (i.e. There is no application that can make use of this index).
And if you decide to have a foreign key parent_id then I suggest to have too many indexes on parent_id because it would be at least useful when you delete a record in this table.Best regards!
Maybe you are looking for
-
How can I make the size of the show all windows bookmarks?
When I click on show all bookmarks, that the window is full screen. I can't leave this page without stopping Firefox window.
-
I have a new drive hard because my old operating system from hard disk (windows) is not booting. So I have a new hard drive with the new mode of system (windows). What I want is I want to search the places.sqlite file in my older hard disk which is c
-
Audio Fadin incoming and outgoing, but the video quality remains high.
Hello. I am regularly skyping someone, but the incoming audio signal began fade in and out and sometimes mute altogether. The video quality is very good and she can still hear and see me OK. The volume for Skype and everything else is wound up to the
-
Satellite U400-10W (PSU40E): need of BIOS to fix the battery problem
Hello I already have a Satellite U400-10W (PSU40E) with the issue reported in the technical knowledge base (the battery is not recognized and does not load after a long period without power). To solve this problem I need a bios or above 3.0 but the l
-
HP ENVY 15 - j028tx: HP ENVY 15 (windows 10) fingerprint problem
I have upgraded to windows 10 and the fingerprint driver no longer works. I decided to install the new driver on the site of hp drivers and after the installation of the new driver, it shows a symbol yeow in Device Manager and still does not work. my