Difference between the immediate and normal constraint primary key value

Hello
I tried the following to understand the difference between immediate constraint set and the primary normal stress
create table cust (cust_id number ,cust_name varchar2(25));

alter table cust add constraint cust_id_pk primary key(cust_id)
deferrable initially deferred;

SQL> insert into cust values(1,'raj');

1 row created.

SQL> insert into cust values(1,'sam');

1 row created.

SQL> commit;
commit
*
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-00001: unique constraint (SCOTT.CUST_ID_PK) violated


SQL> set constraint cust_id_pk immediate;

Constraint set.

SQL> 
SQL> insert into cust values(1,'lata');

1 row created.

SQL> insert into cust values(1,'lata');
insert into cust values(1,'lata')
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.CUST_ID_PK) violated
The above error violation even works for a normal constraints primary / unique

So what is the use of the command

immediate Set constraint cust_id_pk;


Thank you

So what is the use of the command

In fact, the use of the command when you're dealing with foreign key constraints. As explained below

 SQL>  create table cust (cust_id number ,cust_name varchar2(25), supplier_id number);

Table created.

SQL> create table supp(supplier_id number);

Table created.

SQL> alter table supp add primary key(supplier_id);

Table altered.

SQL>  ALTER TABLE cust ADD CONSTRAINT fk_cust_supp
  2    FOREIGN KEY (supplier_id)
  3    REFERENCES supp (supplier_id)
  4    DEFERRABLE
  5    INITIALLY deferred;

Table altered.

To insert a line in the cust table without entering Ref provider table supp

SQL> insert into cust values(1,'raj',111);

1 row created.

Line by 1 created successfully (attention this validation is not yet done) because the foreign key constraint is initially deferred.

Now

SQL> set constraint fk_cust_supp immediate;
set constraint fk_cust_supp immediate
*
ERROR at line 1:
ORA-02291: integrity constraint (OWNER.FK_CUST_SUPP) violated - parent key not found

Since Ref no outs in extra table so forced provider violated.

allows to insert a row in the vendor corresponding with the vendor id in the cust table id

SQL> insert into supp values(111);

1 row created.

Now, try

SQL> set constraint fk_cust_supp immediate;

Constraint set.

but now, if you try to insert a row into the table cust without this vendor id in table supp, it give error (since now forced to check from the inserted row, even will not wait for commit)

SQL>  insert into cust values(3,'bob',222);
 insert into cust values(3,'bob',222)
*
ERROR at line 1:
ORA-02291: integrity constraint (OWNER.FK_CUST_SUPP) violated - parent key not found

Also, in the case of primary key constraints will be checked when you perform VALIDATION, otherwise that it will allow you to insert the second row.

SQL> alter table cust add constraint cust_id_pk primary key(cust_id)
  2  deferrable initially deferred;

Table altered.

SQL> insert into cust values(1,'raj');

1 row created.

SQL> insert into cust values(1,'sam');

1 row created.

SQL> insert into cust values(1,'bob');

1 row created.

SQL> commit;
commit
*
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-00001: unique constraint (OWNER.CUST_ID_PK) violated

SQL> 
SQL> drop table cust;

Table dropped.

SQL> create table cust (cust_id number ,cust_name varchar2(25));

Table created.

SQL> alter table cust add constraint cust_id_pk primary key(cust_id)
  2  deferrable initially deferred;

Table altered.

SQL> set constraint cust_id_pk immediate;

Constraint set.

SQL> insert into cust values(1,'raj');

1 row created.

SQL>  insert into cust values(1,'sam');
 insert into cust values(1,'sam')
*
ERROR at line 1:
ORA-00001: unique constraint (OWNER.CUST_ID_PK) violated

SQL> 

Published by: Azhar Husain on July 27, 2011 12:01

Tags: Database

Similar Questions

  • What is the difference between the stop and restart?

    What is the difference between the stop and restart?  I feel that stopping closed all processes, completely erases RAM memory and clears the cache of the processor.  I need to know if 1) this is a correct assumption and 2) which is better for daily maintenance of the system.  Thank you in advance.

    Hello Jeremy_1976,

    Your support when the judgment is correct. Basically, it stops the process and completely turns off your computer. Reboot, however, temporarily your PC stops, then turn it on again. This happens usually when Windows updates are installed. After installation, the system is restarted (rebooted) so that any update has been successfully installed and works as it should. You can be a little mixed upward the reboot and the hibernation. Reboot is, as I have indicated previously, basically a reboot of your machine. Ultimately, your PC is on again after a reboot. However, hibernation, stores all data currently in memory in a special file, then the PC turns off. When you then turn on your PC, that is, coming out of hibernation, hibernation files is used to restore the status of the PC than when you initially put into hibernation. In other words all the programs you had open before will automatically open and be ready to use hibernation.

    Hibernation or sleep for that matter is for short-term use. It is normal in Hibernate, or sleep if you want to be away from your PC for half an hour or so. If you leave more than I suggest you stop completely.

    A point to remember about hibernation is that, if you use put into hibernation, you can't, once you get out after hibernation, install programs or updates. You have to stop and restart normally to do.

    This forum post is my own opinion and does not necessarily reflect the opinion or the opinion of Microsoft, its employees or other MVPS.

    John Barnett MVP: Windows XP Expert associated with: Windows Expert - consumer: www.winuser.co.uk |  vistasupport.mvps.org | xphelpandsupport.mvps.org | www.silversurfer-Guide.com

  • Difference between the trainer and plaintiff on a purchase requisition?

    Hello

    What is the difference between the trainer and the applicant on a purchase requisition?

    Where this information is stored in the database?

    Is there a standard on report box to find it.

    We want a report that gives information on which arouses requests on behalf of others.

    This report is an audit report.

    Thank you very much

    Emily

    What is the difference between the trainer and the applicant on a purchase requisition?

    Trainer - who prepares the document however applicant who is (concern the team or Department) request the material.  Normally preparer is the true owner of the document and control of the applicant manages the material to the organization once he sent by the provider.

    Where this information is stored in the database?

    PO_requisition_Lines_all holds the to_person_id the details of the applicant and created_by is trainer details.

    Is there a standard on the gear to find it

    Try the 'Purchase requisition Status Report' report, given the details of the applicant & trainer of the requisition.

    concerning

    Madhu

  • What is the difference between the CACHE and the PIN code?

    What is the difference between the CACHE and the PIN code?

    Cached, it's when you specify CACHE as part of a CREATE or ALTER an object to say Oracle when the blocks are retrieved this object these blocks should be put to the most recently used end of the LRU (least recently used) list in the buffer cache when a full table scan. Under normal circumstances, when the blocks are retrieved in memory, in that they are placed least recently used end of the LRU list. This means that the data that was most recently viewed typically will remain available in the cache buffers for awhile. Therefore, subsequent runs of the same query should find these blocks already in the buffer cache and not to recover disk again. When you use the CACHE, you say you want to put the blocks retrieved at the end of the list, which means that they will be the first blocks "aged" off the buffer cache when more space is needed.
    A few reasons to use the CACHE are:
    (1) for tables of small (only a few blocks that must be read to retrieve the entire table).
    (2) when you do a select statement returns a huge amount of data, and you do not necessarily have if wait for the query to run any time soon. In both cases, you give Oracle an opportunity to eliminate the blocks quickly to make room for more 'necessary' blocks instead of having to follow in the LRU list.

    Pinning is when you want to keep the objects in memory and to prevent them from being aged by the normal mechanism of the LRU. You use the INVALIDHTOMEH to "pin" PL/SQL code in memory, so that users are not experiencing intermittent slowdowns when code gets years out of the shared pool and must be recharged.

    The bottom line is that caching can blocks be moved quickly while pinning retains the information in memory to avoid the re-loads.

  • What is the difference between the password and access code

    I get all the IDs and passwords and none are accepted

    "I received message' iPad requires your password after restart", but it does not accept passwords

    What is the difference between the password and access code

    Standard codes which block the iPad are 4 or 6-digit. You can set a more difficult to decode, personalized access code / password in the settings using letter and numbers if you wish.

    A password is a series of numbers, symbols and letters that a user putting in place to protect the information in a frame, a web site, e-mail, etc. This may actually be a word or series of words, if you wanted to set up in this way.

    Your iPad is looking for this 4- or 6-digit code. If you can remember, you must restore the device so for free.

    If you have forgotten the password for your iPhone, iPad or iPod touch, or your device is disabled - Apple supports

  • Difference between the G20 and G25 models

    Hi people!

    I searched your laptop and I was amazed by the Qosmio.
    When I was going to order it, I noticed that there are many models of the G20 with different specifications. Also, I found G25 on internet research and found no difference between the G25 and G20 except receiver TV G25 is NTSC and G20 was released on March and G25 was in June. Instead, they have the same specifications for the hard drive.

    I live in the Portugal and the model Qosmio I can find that this is the G20-118. I was looking for the model that has 2 x 100 GB SATA HD, but cannot not thought about it.

    Internet research I found Qosmio G20-111 which has 2 x 100 GB SATA HD, but on the web page mentioned that it was a Pentium III processor (ridiculous, isn't?). I was looking for more reliable information.

    Already searched for toshiba pages and found no specifications for all models I found 490LS on the research on the web as the G20 - 102, 105, 106, 108, 109, 111, 118, 123,...

    Can someone help me with this? Are there any reliable web page where I can see the differences between the models? is there a .pdf or anyone who can please give me some advice?

    Money is not a problem at this time to acquire the laptop, I'm looking for only the laptop performance more!

    Best regards
    João Pereira

    Hello

    It of very difficult to say what camera is best, because there are many models with different parts.
    However, I found page with description of the G20 and G25.
    Take a look at this link.

    http://www.releasereview.com/Toshiba-Qosmio-G20-105-108-114.aspx?d=0101000580926052005

    Good bye

  • What is the difference between the iwatcha and the Apple Watch?

    What is the difference between the iwatch and Apple Watch?  In the sales pitch pre for the iwatch, the price was given to about $17,000, while the Apple Watch sells in the $350-500 range. What gives?

    There is no such thing as a iWatch.

    There are three versions of the Apple Watch.

    Apple Watch Sport

    Apple Watch

    Apple Watch Edition

    https://www.Apple.com/watch/buy/

  • geometric matching: difference between the scores and correlation

    Hi all

    What is the difference between the scores and correlation in geometric correspondence?

    Hello

    the correlation score is based on pixel intensities while the score of the geometric game also considers the characteristics of the geometry. See the Concepts of Vision or (geometric matching-> discussion).

    I hope this helps.

    Best regards

    K

  • What is the difference between the IO and line?

    Hi all

    I'm using Labview 7 and in my mahcine I have an installed 6013 card. However, there was an interface card designed by someone else long ago, on the table, only AO0, AO1,..., A07, DIO0, DIO1,..., DIO7 were printed. In the program, I saw some code to write to digital Line.vi allows you to send data to the digial io. Say that I write for DIO 3, so I understand here DIO 3 means the channel of e/s 3, but online? What is the difference between the channel and the line? When I write the data to a single channel of e/s, are us wriitng a byte or a bit of it? Thank you.

    A channel is usually used with inputs/outputs analog.  Each AI or AO is a string.

  • 8.5.1 LabVIEW Student Edition - differences between the Mac and Windows versions?

    Hello

    I just bought the student of LabVIEW 8.5.1 version and I use Mac OS X 10.4.11. What are the biggest differences between the Mac and Windows versions, since the box came with a CD of installation of Mac and a Windows DVD Installer?

    See you soon

    Looks like you got the LabVIEW Student Edition Software Suite DVD.

    It comes with 6 boxes to tools, and the TME product, some (or all?) of those who are windows only (at least 8.5), for example:

    • Toolkit Digital Filter Design
    • Modulation Toolkit
    • SignalExpress
    • ...

    Since you have 8.5, you are missing also a few basic things that only recevied at the 8.6MAC support, like Mathscript, Control design and Simulation and native 3D graphics.

  • Major difference between the Group and the organizational unit?

    Pls explain me what is the difference between the groups and the organization unit in simple terms with an example in real time.

    Hello

    https://en.Wikipedia.org/wiki/Organizational_unit _ (computing)

    https://en.Wikipedia.org/wiki/Group _ (computing)

    See you soon.

  • What are the differences between the services and site domain group policy and group policy?

    What are the differences between the services and site domain group policy and group policy?

    Server must wonder about the Technet site.  http://social.technet.Microsoft.com/forums/en-us/home

  • There are the functional differences between the trial and the full version?

    There are the functional differences between the trial and the paid version for Labview 2009?  Thank you.

    He described the Labview eval version limitations: Limitations of the Evaluation Version of LabVIEW

    See you soon,.

  • What is the difference between the KING and ACQWINDOW regarding the attributes of the camera?

    There are two sets of attributes for, left, top, width, and height.

    For example, there

    IMG_ATTR_ROI_WIDTH vs IMG_ATTR_ACQWINDOW_WIDTH

    MG_ATTR_ROI_HEIGHT vs IMG_ATTR_ACQWINDOW_HEIGHT

    What are the differences between the KING and ACQWINDOW?

    Thank you.

    Hi sunspotzsz!

    Vision consists of two main steps: acquisition and image processing.  IMG_ATTR_ACQWINDOW_WIDTH would the acquisition, and IMG_ATTR_ROI_WIDTH should be part of the treatment.  Therefore, if you set the ACQWINDOW_WIDTH to 100 so that numbers all pixels that are acquired will be set to 100, and they will be stored in a buffer.  ROI_WIDTH will use an image that is already in memory and 'zoom' so that the only part of the image you are watching / treatment.

    Also, take a look at this knowledge base on the Kings: KING FAQ you may find it useful!

    Kristen H.

  • Difference between the administrator and built-in Administrator

    What are the differences between the administrator and built in Administrator?

    Built in Administrator account has all of the control of the computer, UAC does not run when you run the built-in Administrator account.

    But in the standard Admin account, User Account control is running.

    In windows 7 and later versions built in admin account exists, but is disabled.

    It will be useful.

Maybe you are looking for