Home > Ask the Oracle Experts > Database Design and Architecture Questions & Answers > Oracle does not maintain order of inserted records
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Oracle does not maintain order of inserted records

Brian Peasland EXPERT RESPONSE FROM: Brian Peasland

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Oracle tips, scripts, and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 14 May 2007

I am facing a pretty unusual problem. I have two tables, A and B. When I insert some value in table A, a trigger will be initiated and the same sum of the column values will be populated in table B from table A. At a time 5,000 records are inserted in table A and hence, similarly in table B. The requirement is to have records in table B sorted w.r.t the primary key. But, Oracle has the problem of not maintaing the order in the way records were inserted. So, the approach that I followed is:

1. Create clustered index (i.e., index organized table) in both the tables w.r.t their primary key. Then I performed insertion. It worked fine -- the order of insertion was the same as the order of storing the records in both the tables (table B being populated by trigger). But I faced some other issue here. When I delete some record from table B and then insert a record, the order of insertion was not maintained. The records become haphazardly stored. I want the records to be appended after the last record.

2. To resolve the issue I faced in Step 1, I tried to use the direct-path insert method which says that the records to be added in the table will be appended to the last record present in the table. For this, I modified the trigger (which is responisble for populating table B) to use /*+Append*/ option. But still this doesn't work.

Can anyone provide me with the solution? Please don't tell me to use the "Order By " clause while fetching records from Table 2, since fetching the record is not in my control (records are fetched and deleted by BEA control -- and it needs the ordered records). The only thing I can do is to insert the record in proper order in the table.


>
EXPERT RESPONSE
No relational database can guarantee order in a table. That is precisely why the ORDER BY clause was created for your SELECT statements. In my entire DBA career, I have never had to care about the physical ordering of rows within a table. If I wanted to pull the data out in a particular order, I use the ORDER BY clause. If you consult other experts in relational database design, they will tell you to rethnk your design. And that is my suggestion to you as well. That being said, if you still feel you need this requirement, then I would point you towards the Indexed Organized Table data structure, which will maintain a sort order based on the index key.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
Database Design and Architecture
Should we worry about Oracle memory leaks on Windows?
How to disable Oracle constraints and triggers during an import in 10g
How to delete a partition on the F: drive with Oracle on Windows
What could be causing an SQL count 0 with a successful Oracle import?
What is a staging table, and how is the staging concept used in Oracle?
Tips for how to size an Oracle server
Oracle error 942 when exporting a schema
Do DDL statements roll back, and why?
Increasing Oracle storage capacity by moving to a new storage with minimum downtime
Using Undo Tablespaces vs. rollback segments in Oracle 9i, 10g

Oracle database design
Oracle database in the cloud floated at Harvard lab
Oracle OpenWorld 2008 Special Report
Weighing remote database administration pros and cons takes care
Oracle Database 11g makes waves at Burlington Coat Factory
How to create a database link in Oracle
Data modeling tools no substitute for hard work
How do I do that in Oracle?
The Oracle Database user's guide to Oracle OpenWorld 2007
Oracle OpenWorld 2007 Special Report
How many redo log files?

The relational model
Happy birthday Oracle -- 30 years!
Retrieve last row inserted into table in Oracle
Relationship between schema and datafile in Oracle
Why is Oracle 8 an "ORDBMS"?
Mike Ault's Oracle "good practices": Oracle design
Oracle revamps TimesTen In-Memory Database
Geeks pick the top movies of 2007
Network model for databases
Network, hierarchical and relational data models
Database vs. relational database

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
extent  (SearchOracle.com)
field  (SearchOracle.com)
flexfield  (SearchOracle.com)
foreign key  (SearchOracle.com)
quad tree  (SearchOracle.com)
record  (SearchOracle.com)
row  (SearchOracle.com)
splay tree  (SearchOracle.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts