What are the surrogate key and row_number( )

what are the surrogate key and row_number( ) function, and why do not we always make the row_number a primary key in the table.

Mohannad,
we just try to safe your efforts and to prevent common
mistakes you can make.
Look here.
Your requirement is to avoid gaps in sequence.
OK. But it means you HAVE to lock your sequence
exclusively until you commit transaction.
Also, it means you have to rollback sequence
number to original value if you rollback you
entire transaction.
SQL> create table my_tab (id number);
&nbsp
Table created.
&nbsp
SQL> create table numer_tab (id number);
&nbsp
Table created.
&nbsp
SQL> insert into numer_tab values(0);
&nbsp
1 row created.
&nbsp
SQL>  create or replace trigger
  2   tr_no_gap
  3   before insert on my_tab
  4   for each row
  5   begin
  6    /* Let's lock sequence in exclusive mode */
  7    update numer_tab set id = id + 1
  8    returning id into :new.id;
  9   end;
10  /
&nbsp
Trigger created.Now I havn't to worry about gaps:
Fisrt session:
SQL> insert into my_tab values(null);
&nbsp
1 row created.because my next session is waiting:
SQL> insert into my_tab values(null);
&nbspI do commit in first and second session -everything is OK:
SQL> commit;
&nbsp
Commit complete.
&nbsp
SQL> select * from my_tab;
&nbsp
        ID
         2
         1Now I do the same but do rollback in 1th:
SQL> insert into my_tab values(null);
&nbsp
1 row created.
&nbsp
SQL> rollback;
&nbsp
Rollback complete.and commit in 2th:
SQL> insert into my_tab values(null);
&nbsp
1 row created.
&nbsp
SQL> commit;
&nbsp
Commit complete.No gaps:
SQL> select * from my_tab;
&nbsp
        ID
         2
         3
         1Now I will not lock sequence resource due a transaction:
SQL>  create or replace trigger
  2   tr_no_gap
  3   before insert on my_tab
  4   for each row
  5   declare
  6    pragma autonomous_transaction;
  7   begin
  8    /* Let's lock sequence in exclusive mode */
  9    update numer_tab set id = id + 1
10    returning id into :new.id;
11    commit;
12   end;
13  /
&nbsp
Trigger created.And I repeate my last operation.
Both inserts execute immediately
1th
SQL> insert into my_tab values(null);
&nbsp
1 row created.2th
SQL> insert into my_tab values(null);
&nbsp
1 row created.Now I rollback the first and commit the second.
And what I see is the gap:
SQL> select * from my_tab;
&nbsp
        ID
         2
         3
         5
         1We are just trying to explain what you will have to
pay the serious price of performance in the
absence of gaps and you will have the lack
of Oracle multithreading advantage in this case.
I doubt your customers will happy with that.
Rgds.

Similar Messages

  • What are the shortcut keys Ü and ÿ?

    Hi! In the german version of ID CS6 some shortcut keys are not exactly clear. What keys do I need to press to show or hide the help lines?

    Even a fresh install can be damaged, you know. I had the hardest time getting my Middle East edition to install correctly until I uninstalled my Lao keyboard software.
    Bug reports can be filed here, but you won't hear any resolution from Adobe unless you start a support case.
    I'd be more sympathetic to your frustration if the fix wasn't so damned easy. But since I'm a localization wonk, I fix problems like this every day - it's in the job description.  
    I think that their testing is limited to most-common-use-case scenario. I dunno if there is a Swiss-German locale for ID CS6 (there is one for CC), but I really doubt that they'd test the default-German install with a Swiss keyboard. It's just about as likely as, you know, a Romansh locale for ID.

  • What are the shortcut keys for new tab page?

    It looks like the new tab page (Firefox 13, with the
    screenshots of your popular pages in it) is a mouse-only
    feature.
    Is this correct? What are the shortcut keys to access
    the links on the page?
    thanks,
    Patrick

    Hi,
    As of now there aren't (most likely) keyboard shortcuts. Please also see [https://support.mozilla.org/en-US/kb/new-tab-page-show-hide-and-customize-top-sites this] for working with the new tab page.

  • What are the logical structure and physical structure in oracle

    what are the logical structure and physical structure in oracle and how can allocate a DB block size as default size is 8192?

    From the Concepts Guide
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14220/toc.htm
    The physical structures are:
    Datafiles
    Control Files
    Redo Log Files
    Archive Log Files
    Parameter Files
    Alert and Trace Log Files
    Backup Files
    The Logical Structures are:
    Tablespaces
    Oracle Data Blocks
    Extents
    Segments

  • My iSight is not working on my Macbook Pro. What are the possible problems and solutions?

    My iSight is not working on my Macbook Pro. What are the possible problems and solutions?

    Hello Douglas,
    Thank you for the details of the issue you are experiencing with the built-in iSight camera on your MacBook Pro.  I recommend the following steps for this issue:
    Important: Follow these instructions in order. Test the camera between steps to see if the issue is resolved.
    Built-in iSight cameras
    These steps are for iSight cameras that are built into a computer, such as the iMac G5 (iSight) or later, the MacBook, or MacBook Pro.
    See if the issue is application-specific.
    Try another application (iSight works with applications like iChat, PhotoBooth, and iMovie HD 6) to see if the iSight camera exhibits the same behavior in all applications. If it only happens in one application, try reinstalling that application.
    See if the issue is user-specific.
    Test your iSight camera in another user account. If the issue only occurs in one user, the issue would be isolated to user settings.
    Find out if the computer recognizes the iSight
    Check System Profiler (in the Utilities folder, inside the Applications folder). Under the USB header, check to see if the iSight camera is detected.
    Reset SMC or PMU
    Reset your computer's SMC or PMU, and then check System Profiler again. (SMC reset instructions for iMac G5 (iSight), Intel-based iMacs; PMU reset instructions for MacBook and MacBook Pro.)
    If your built-in iSight camera is still not behaving correctly after trying all these steps, you may need to contact Apple or an Apple-Authorized Service Provider for service.
    You can find the full article here:
    How to Troubleshoot iSight
    http://support.apple.com/kb/ht2090
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • What are the different tools and techniques available to track analytics in SharePoint online 2013?

    I want to know What are the different tools and techniques available to track analytics in SharePoint online 2013. Please provide your suggestions/ inputs. Thanks in advance.

    you can Use the Web Analytics Integration app  to
    connect your SharePoint Online public website to third-party web analytics services, such as Webtrends, Google Analytics, Adobe, and so on.
    Google Analytics
    Webtrends for SharePoint
    CARDIOLOG ANALYTICS
    Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog

  • What are the pro's and con's of the 4s?

    I am not yet an owner of the 4s iphone. So what are the pro's and con's of owning the white 32gb iphone 4s? I have had the white 32 gb iphone 3gs for two years and until I get a job I will not be buying the 4s I so need.

    Samplers do alot of things, what do you need a sampler for?
    Korgs remind me of alot of presets and alot of verb and chorus. I guess if you're posting here you already have EXS and want more sounds or more functionality and if the korg thing is true you lean more to sampling/synthesis than instrument recreation (as in you probably aren't going for VSL if the korg caught your ear). Independence looks really cool, it's quite new. Kontakt is demanding and very flexible, both include huge libraries and I know kontakt has tons of great filters, FX, modulation. It also needs a pretty strong update-which is being dealt with after a year or so.

  • What are the physical topology and logical topology in sharepoint

    Hi
    what are the physical topology  and logical topology in sharepoint
    how to define  the physical topology  and logical topology in
    sharepoint
    adil

    Here are the example topologies for SharePoint:
    Traditional - 
    http://www.microsoft.com/en-us/download/details.aspx?id=30377
    Streamlined - 
    http://www.microsoft.com/en-us/download/details.aspx?id=37000
    Trevor Seward
    Follow or contact me at...
    &nbsp&nbsp
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • I am trying to connect my iMac with my MacBook What is the command keys and process in doing so. Have firmwre in place.

    I am trying to connect my iMac with my MacBook What is the command keys and process in doing so. Have firmwre in place.

    Here's the Apple Support article on Target Mode http://support.apple.com/kb/HT1661

  • What are the delta mechanisms and tables used for  Lo Extraction & COPA

    Hi all
    what are the delta mechanisms and tables used for  Lo Extraction & COPA.
    please explain clealry.
    Thanks & Regards,
    James

    James,
    Please go through Roberto's weblog :
    /people/sap.user72/blog/2005/02/14/logistic-cockpit--when-you-need-more--first-option-enhance-it
    Anyways,
    As you know LO cockpit consists of different modules(MM, PP, SD, etc)
    They are called appl components. Each of them have a number (eg.MM=02) and for each appl comp they might be different Data sources and for each DS they might be different tables. So, unless you be specific we cant tell a specific table for a DS.
    coming to the delta mechanisms, there are " direct delta, queqed delta and serialized delta".
    Copa is based on the oepration concern. it can be created on " accouting based" or "costing based".
    Assign points if helpful
    Kalyan

  • What are the BEST Books and Best websites for java biginners?

    Dear All,
    What are the BEST Books and Best websites for java biginners-Especially for fast learning.
    Thnaks
    KMK

    This is my standard reply:
    [Sun's basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
    [Sun's New To Java Center|http://java.sun.com/learning/new2java/index.html]
    Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    jGuru
    A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch
    To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    [Yawmarks List|http://forums.devshed.com/java-help-9/resources-for-learning-java-249225.html]
    [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance]
    [http://javaalmanac.com|http://javaalmanac.com]
    Bruce Eckel's [Thinking in Java(Available online.)|http://mindview.net/Books/DownloadSites]
    Joshua Bloch's [Effective Java|http://www.amazon.co.uk/exec/obidos/Author=Bloch,%20Josh]
    Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance ]
    James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806]
    Gosling is the creator of Java. It doesn't get much more authoritative than this.
    Joshua Bloch and Neal Gafter [Java Puzzlers.|http://www.javapuzzlers.com/]

  • What are the disc space and memory requirements for the apps?

    What are the disc-space and memory requirements to run the apps

    Hello John!
    thank you for the info. However, as I have only 1Gb memory and a 32Gb
    solid-state disc, I think that I will stay with Acrobate.com for a while
    longer.
    Regards
    Brianb

  • What are the supported Platforms and system requirements for JSE?

    What are the supported Platforms and system requirements for JSE?

    Hi There,
    The following are the system requirements & the support platforms for JSE :-
    * Solaris 9 and 8 Operating Systems (SPARC Platform Edition)
    o UltraSPARC II 450-MHz system with 512 MB of memory and 850 MB of disk space
    o Recommended: UltraSPARC III 750-MHz system with 1 GB of memory and 1 GB of disk space, or higher.
    * Solaris 9 Operating System (x86 Platform Edition)
    o Pentium III 500-MHz system with 512 MB of memory and 850 MB of disk space
    o Recommended: Pentium III 1-GHz system with 1 GB of memory and 1 GB of disk space, or higher
    * Windows 2000 and Windows XP
    o Pentium III 500-MHz system with 512 MB of memory and 850 MB of disk space
    o Recommended: Pentium III 1-GHz system with 1 GB of memory and 1 GB of disk space, or higher

  • What are the defaul username and password for SQL Plus ?

    hello, what are the defaul username and password for SQL Plus ? i'm using the client 11.2.0.1

    You'll need to download the full database installation files for the platform you are using. They are two .zip files, about 2.2 gig total.
    I'm not going to give you the link because you should be able to find it easily. You have to read and accept the license agreement anyway.
    When you install it, you'll be given several options about the type of database you want.
    But before you install anything, you should read the installation manual for your platform.

  • What are the available software and apps for ipod nano

    what are the available software and apps for ipod nano

    saif78 wrote:
    what are the available software and apps for ipod nano
    Sorry, but Apps are not compatible with the iPod and there is no additional software available for it.
    B-rock

Maybe you are looking for

  • Unable to save Sequence value to Database

    Hi, I am trying to pupulate a sequence value so that I can use it as primary key along with the combination of other columns later. My problem is that the sequence value is getting populated on the page with the right value, But is not getting saved

  • Inbox showing 0 messages or correct # of new msg but old state on click

    I think the problem occurs for many users but couldn't find a post giving a summary of this issue. System: one account, IMAP/Exchange 10.4.10/10.4.11 Problem: Starting from normal operation at some point the INBOX seems to become inconsistent. I thin

  • Automatic incidents in Solution manager

    Hello all, At first, I am not SolMan consultant...so maybe my issue is not so difficult for you. Customer use FM AI_CRM_IM_INCIDENT_CREATE to automatically create incidents in some cases. They added some customer fields to the incident (message type

  • List Split icons

    In dreamweaver CS6 - In the JQuery Mobile swatches, the List Split Icons are not displaying,  even once data-split-icon is allocated. Anyone else having this issue?

  • Can we monitor Sun Cluster events

    Hi, Whenever there are some events, issues in cluster, we see logs on the node consoles regarding the same. Is there any way to capture these events through some other application? Better, is there any way by which we can send these events, in some s