DEFERRABLE Constraint State Meaning ??
Hello,
I checked the documentation about the meaning of DEFERRABLE constraint state here and in particular following section
DEFERRABLE Clause
The DEFERRABLE and NOT DEFERRABLE parameters indicate whether or not, in subsequent transactions, constraint checking can be deferred until the end of the transaction using the SET CONSTRAINT(S) statement. If you omit this clause, then the default is NOT DEFERRABLE.
Specify NOT DEFERRABLE to indicate that in subsequent transactions you cannot use the SET CONSTRAINT[S] clause to defer checking of this constraint until the transaction is committed. The checking of a NOT DEFERRABLE constraint can never be deferred to the end of the transaction.
If you declare a new constraint NOT DEFERRABLE, then it must be valid at the time the CREATE TABLE or ALTER TABLE statement is committed or the statement will fail.
Specify DEFERRABLE to indicate that in subsequent transactions you can use the SET CONSTRAINT[S] clause to defer checking of this constraint until after the transaction is committed. This setting in effect lets you disable the constraint temporarily while making changes to the database that might violate the constraint until all the changes are complete.What I understood from above was if the constraint is created as DEFERRABLE, then it is possible to change its status to DEFERRABLE(i.e. check the validity at the end of transaction) / IMMEDIATE(i.e. check the validity at the end of statement). However, my following test shows that just having constraint defined as DEFERRABLE is enough to postpone the constraint validation to the end of transaction. Is the documentation incorrect or am I missing something obvious here?
SQL> select * from v$version ;
BANNER
Oracle Database 10g Release 10.2.0.5.0 - Production
PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
SQL> DROP SEQUENCE P_SEQ ;
Sequence dropped.
SQL> DROP TABLE C PURGE ;
DROP TABLE C PURGE
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> DROP TABLE P CASCADE CONSTRAINTS PURGE ;
Table dropped.
SQL> CREATE TABLE P (PID NUMBER, CONSTRAINT P_PK PRIMARY KEY (PID)) ;
Table created.
SQL> CREATE SEQUENCE P_SEQ minvalue 1 start with 1 increment by 1 cache 10 ;
Sequence created.
SQL> CREATE TABLE C (CID NUMBER, PID NUMBER, CONSTRAINT C_PK PRIMARY KEY (CID), constraint c_fk foreign key (pid) references P(PID) deferrable initially immediate) ;
Table created.
SQL> select CONSTRAINT_NAME, TABLE_NAME, R_CONSTRAINT_NAME, status, DEFERRABLE, DEFERRED from USER_CONSTRAINTS ;
CONSTRAINT_NAME TABLE_NAME R_CONSTRAINT_NAME STATUS DEFERRABLE DEFERRED
C_FK C P_PK ENABLED DEFERRABLE IMMEDIATE
P_PK P ENABLED NOT DEFERRABLE IMMEDIATE
C_PK C ENABLED NOT DEFERRABLE IMMEDIATE
SQL> CREATE OR REPLACE TRIGGER C_BI_TRG
2 BEFORE INSERT ON C
3 FOR EACH ROW
4 BEGIN
5 IF :NEW.PID IS NULL THEN
6 INSERT INTO P VALUES (P_SEQ.NEXTVAL) RETURNING PID INTO :NEW.PID ;
7 END IF;
8 END;
9 /
Trigger created.
SQL> SELECT * FROM P ;
no rows selected
SQL> SELECT * FROM C ;
no rows selected
SQL> INSERT INTO C VALUES (1, NULL) ;
1 row created.
SQL> SELECT * FROM P ;
PID
1
SQL> SELECT * FROM C ;
CID PID
1 1
SQL> commit ;
Commit complete.
You are right, I overlooked that. Example about the difference:
SQL> create table t (n number);
Table created.
SQL> alter table t add constraint c primary key (n) deferrable initially immediate;
Table altered.
SQL> insert into t values (42);
1 row created.
SQL> commit;
Commit complete.
SQL> insert into t values (42);
insert into t values (42)
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.C) violated
SQL> alter session set constraints=deferred;
Session altered.
SQL> insert into t values (42);
1 row created.
SQL> commit;
commit
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-00001: unique constraint (SCOTT.C) violatedKind regards
Uwe Hesse
http://uhesse.wordpress.com
Similar Messages
-
I just wanted to make sure I have deferred constraints understood:
If we declare a constraint as DEFERRED, this means that the user may change the behavior of that constraint later, using ALTER SESSION, or SET CONSTRAINT statements.
The user can change the constraint to INITIALLY DEFERRED so that the statement is only checked at the end of a transaction (commit).
Is this correct? There must be this sort of two step approach to it - first having the constraint declared as DEFERRED, then allowing it to be managed later using INITIALLY DEFERRED. ?You are right it's two steps, first you have to create the constraint DEFERRABLE
and you define it INITALLY DEFERRED or INITIALLY IMMEDIATE. If it's created deferable then you can alter wether it'S initially immediate or defered.
You can find more information here
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/clauses002.htm#g1053592
Regards,
PP -
Difference between non deferrable constraint and initially immediate defferable constraint
Hi,
what is the difference between nondeferrable and initially immediate deferrable constraint. In concepts11g guide it's mentioned that database apply constraint at the end of statement.
thanks,
alokThere are two concepts here.
First whether or not the constraint can be deferred, That is what the deferrable clause controls. By default all constraints are enforced at the time the statement is issued, that is, when you issue an insert statement, all constraints are checked before the data is actually inserted, and if any constraint checks fail you will receive an error. When a constraint is declared as deferrable, that means that you can put off the constraint checking until the end of the trasnaction (i.e. commit time).
The initially clause determines what the "default" behaviour for a deferrable constraint will be. If you say initially immediate, then it will behave exactly the same as a non-deferrable constraint. If you say initially deferred, then constraint checking will be postponed until the end of the transaction (which could be several different SQL statements). If you have a deferrable constraint, either initially deferred or immediate, you can alter the behaviour for a particular transaction by issueing an alter constraint statement to set either one constraint (by specifiying the constraint name) or all deferrable constraints (by specifying all) to either immediate or deferred. The behaviour will revert back to whatever was defined at the time the constraint was created when you issue a commit ot rollback.
John -
DEFERRABLE constraints - error
Hi,
I am trying this example for DEFERRABLE constraints.
CREATE TABLE chicken(cID INT PRIMARY KEY,
eID INT);
CREATE TABLE egg(eID INT PRIMARY KEY,
cID INT);
Then, we add foreign key constraints:
ALTER TABLE chicken ADD CONSTRAINT chickenREFegg
FOREIGN KEY (eID) REFERENCES egg(eID)
INITIALLY DEFERRED DEFERRABLE;
ALTER TABLE egg ADD CONSTRAINT eggREFchicken
FOREIGN KEY (cID) REFERENCES chicken(cID)
INITIALLY DEFERRED DEFERRABLE;
SQL> INSERT INTO chicken VALUES(1, 2);
INSERT INTO chicken VALUES(1, 2)
ERROR at line 1:
ORA-02291: integrity constraint (U2.CHICKENREFEGG) violated - parent key not found
I am getting this error. Why?
Regards,
MathewIf the constraint is deferred it only means that Oracle will check the constraint at COMMIT time. What is Oracle your version ?
I'm only getting this error at COMMIT time with 10.2.0.2:
dev001> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod
PL/SQL Release 10.2.0.2.0 - Production
CORE 10.2.0.2.0 Production
TNS for 32-bit Windows: Version 10.2.0.2.0 - Production
NLSRTL Version 10.2.0.2.0 - Production
dev001> ALTER TABLE egg DROP CONSTRAINT eggREFchicken;
Table altered.
dev001> DROP TABLE chicken;
Table dropped.
dev001> DROP TABLE egg;
Table dropped.
dev001>
dev001> CREATE TABLE chicken(cID INT PRIMARY KEY, eID INT);
Table created.
dev001> CREATE TABLE egg(eID INT PRIMARY KEY, cID INT);
Table created.
dev001>
dev001> ALTER TABLE chicken ADD CONSTRAINT chickenREFegg
2 FOREIGN KEY (eID) REFERENCES egg(eID)
3 INITIALLY DEFERRED DEFERRABLE;
Table altered.
dev001>
dev001> ALTER TABLE egg ADD CONSTRAINT eggREFchicken
2 FOREIGN KEY (cID) REFERENCES chicken(cID)
3 INITIALLY DEFERRED DEFERRABLE;
Table altered.
dev001>
dev001> INSERT INTO chicken VALUES(1, 2);
1 row created.
dev001> commit;
commit
ERROR at line 1:
ORA-02091: transaction rolled back
ORA-02291: integrity constraint (XXXX.CHICKENREFEGG) violated -
parent key not found -
What does 'security setup forms that accept sql statement' mean?
I was referring one white paper 'Best Practices for Securing Oracle E-Business Suite'.
I would like to know what does 'security setup forms that accept sql statement' mean in that?
My question is
Where can the SQL statements be entered?
It would be better if I can have some examples of the same. I am trying to understand this statement.
Edited by: Kavipriya on 30 Mar, 2011 3:37 PMIt is explained in the same docs.
Best Practices for Securing the E-Business Suite [ID 189367.1] -- Page 26, under "LIMIT ACCESS TO FORMS ALLOWING SQL ENTRY" section.
Best Practices For Securing Oracle E-Business Suite Release 12 [ID 403537.1] -- Page 22, under "LIMIT ACCESS TO FORMS ALLOWING SQL ENTRY" section.
Thanks,
Hussein -
What this Syntax or Statement means
What does this statement means.
call 'C_DIR_READ_START' id 'DIR' field file-dir
id 'FILE' field file-name
id 'ERRNO' field file-err
id 'ERRMSG' field file-msg.
Can anyone explain what does it mean ? may be in brief...Hi,
this is OS function used to read the file from a server directory.
like this
Start reading
l_fname = '.'. "Mask
CALL 'C_DIR_READ_START' ID 'DIR' FIELD p_folder
ID 'FILE' FIELD l_fname
ID 'ERRNO' FIELD l_ferrn
ID 'ERRMSG' FIELD l_ferrm.
CHECK sy-subrc = 0.
read Directory
WHILE sy-subrc = 0.
CLEAR l_flist.
CALL 'C_DIR_READ_NEXT' ID 'TYPE' FIELD l_flist-ftype
ID 'NAME' FIELD l_flist-fname
ID 'LEN' FIELD l_flist-fleng
ID 'OWNER' FIELD l_flist-fownr
ID 'MTIME' FIELD l_flist-fmtme
ID 'MODE' FIELD l_flist-fmode
ID 'ERRNO' FIELD l_ferrn
ID 'ERRMSG' FIELD l_ferrm.
CHECK sy-subrc = 0 AND NOT l_flist-fleng IS INITIAL.
l_flist-direc = p_folder.
INSERT l_flist INTO TABLE lt_flist.
ENDWHILE.
finish reading
CALL 'C_DIR_READ_FINISH' ID 'ERRNO' FIELD l_ferrn
ID 'ERRMSG' FIELD l_ferrm.
<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo -
What is the default Constraint States
When we are creating the constraints, we can mention any of the 4 states viz
•ENABLE VALIDATE
•ENABLE NOVALIDATE
•DISABLE NOVALIDATE
•DISABLE VALIDATE
Question is : what is the default states, if we do not mention any one of those.
If possible also give me the oracle document link.
Thanks
Naveen.Question is : what is the default states, if we do not mention any one of those.query USER_CONSTRAINTS for the answer
SQL> desc user_constraints
Name Null? Type
OWNER NOT NULL VARCHAR2(30)
CONSTRAINT_NAME NOT NULL VARCHAR2(30)
CONSTRAINT_TYPE VARCHAR2(1)
TABLE_NAME NOT NULL VARCHAR2(30)
SEARCH_CONDITION LONG
R_OWNER VARCHAR2(30)
R_CONSTRAINT_NAME VARCHAR2(30)
DELETE_RULE VARCHAR2(9)
STATUS VARCHAR2(8)
DEFERRABLE VARCHAR2(14)
DEFERRED VARCHAR2(9)
VALIDATED VARCHAR2(13)
GENERATED VARCHAR2(14)
BAD VARCHAR2(3)
RELY VARCHAR2(4)
LAST_CHANGE DATE
INDEX_OWNER VARCHAR2(30)
INDEX_NAME VARCHAR2(30)
INVALID VARCHAR2(7)
VIEW_RELATED VARCHAR2(14)
If possible also give me the oracle document link.Your answers are just a few clicks beyond the URL below.
http://tahiti.oracle.com
Let us know when you have found your answer. -
Create a table from another table and add constraint statement. Please help
Previously, I post a question and it works as below:
create table my_table
PCTFREE 10 PCTUSED 0 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
TABLESPACE TAB_DATA
as select t1, t5, t2, t3, t4 from orig_table;
I have been trying to use the same strategy as I post earlier, but it doesn't work.
CONSTRAINT "MY_TEMP" UNIQUE ("ID", "SNAME", "CNAME", "TIME", "SYSTEM_ID")
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) TABLESPACE "TAB_DATA" ENABLE
CLUSTER MY_CLUSTER
"CNAME"
Below iis my SQL statement, but it doesn't work. Please help.
create table my_table
CONSTRAINT "MY_TEMP" UNIQUE ("ID", "SNAME", "CNAME", "TIME", "SYSTEM_ID")
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) TABLESPACE "TAB_DATA" ENABLE
CLUSTER MY_CLUSTER
"CNAME"
as (select t1, t5, t2, t3, t4 from orig_table;Hi,
Why do you need to combine the two action togather. You can get the things done in two steps.
Create table tab1 as select * from tab2;
Then you create any contraint that you want to create on tab2 using 'alter table add constraint'.
Regards -
Could anyone explain me what this statements means??Thanks
Hi,
I just reading an ABAP program, found below statement and i am not understand about it...Could you help me? Thanks!!!
it_file-ztext+18(5) to it_inbound_file-box_nbr
As it_file-ztext is an uploaded text file, i am confusing on the '18(5)'...what does this means??
Is it means that only extract the character which started from position18 and the Length is 5?? IS it???
Thanks!!Hi
Yes, You are right
it is field offsetting
it will take just 5 characters starting from 18
example.
str = 'abcdefgh'.
str+4(2) = ef.
<b>Reward points for useful Answers</b>
Regards
Anji -
CTAS with partitions and constraint statement, Is this possible? Help!
I'm trying to use CTAS to create a copy of one of our large tables to test the use of local indexs and partition pruning. Can anyone help me out here? Is this doable or should I go another route? I'm also rearranging the table to put the first column of my primary key as the first column of the table.
Create table new_table,
constraint pk_new_table primary key (seq_number,ssn,service_code)
using index (create index PK_LI_new_table ON new_table (seq_number,ssn,service_code) LOCAL tablespace TS_LI_new_table)
tablespace TS_NEW_TABLE
PARTITION BY RANGE (SEQ_NUMBER)
partition P197203 values less than (2) tablespace ts_new_table_197203,
partition P200906 values less than (245) tablespace ts_new_table_200906
AS SELECT (<new order of columns>) from <original_table>
parallel enable row movement;
output from statement:
Create table new_table,
Error at line 1:
ORA-00922: missing or invalid option
The asterisk is below the comma in the above error statement. Would I need to list out the new table columns and datatypes in the create table statement? Any help appreciated.Hello,
CTAS will not replicate the structure of the source table.
Your best option may be to:
1. Create the empty table that you'll be populating, perhaps using the DBMS_METADATA package:
set pagesize 5000
set long 100000
SELECT DBMS_METADATA.GET_DDL('TABLE','<your_table>','<owner>') FROM DUAL;2. Then INSERT direct-path into that table:
INSERT /*+ APPEND */ INTO new_table (co1, col2, col3,... coln)
SELECT col1, col2, col3,...
FROM source_table;
wolfeet wrote:Would I need to list out the new table columns and datatypes in the create table statement? And you can specify the order of the columns in the INSERT statement above. -
What does a red outline inside a Case Statement mean?
I'm developing some code, and opened an existing VI that has a Queued Message Handler inside it. One Message Case ("Shutdown") has a thin red outline on the inner border of the Case "box" -- what does this mean, where did it come from, and what should I do about it (including "How do I get rid of it?")?.
This code was developed in LabVIEW 2012. I'm pretty sure I haven't seen this previously. I should probably mention that I tested this VI, it quit unexpectedly (possibly by throwing an error somewhere), and I'm looking at the "saved VI".Thanks to GerdW and tst for the rapid responses. Some observations (before this "goes away"). First, right-clicking on a blank space inside the Case Statement brings up the Function palette (oops -- I didn't read your reply carefully -- you said to click the Breakpoint Tool, just a sec -- yep, that does it, but I don't think I've ever used the Breakpoint tool, rather I manage Breakpoints by right-clicking on wires and going from there). Second, I used the Breakpoint Tool to put the breakpoint back on this Case, and brought up the Breakpoint Manager by right-clicking the Error line and choosing Breakpoint Manager. Sure enough, it popped up a notice saying there was one breakpoint set on a Diagram object. When I cleared it, it cleared the top left red border and about 15% of the left side border (at the top), but most of the red border remained until I clicked away from this case then clicked back.
Thanks for the explanation. Where is this noted? I did a search for Case Statement, didn't see it. I suppose if I already knew it was a Breakpoint notification, I could have found it under Breakpoint Help ... (nothing like Knowing the Answer to help you Find the Answer). -
I am able to make it to the site for about 2 seconds and then I am quickly logged off and the statement, "There is a problem with your authentication, possibly due to inactivity. For your safety, you have been logged out and must sign in again to continue."
I don't have a clue as to the problem but since this is impacting my participation in these classes and ultimately could have a negative impact on my grade, I am more than a little concerned!Have you allowed this site to set cookies?
-
What does unreachable statement mean?
I'm trying to write an Exception to prevent a denominator in my program from being 0.
public String toString()
return num + "/" + denom;
if(denom == 0)
IllegalArgumentException exception = new IllegalArgumentException("fractions must not have denominators of zero");
throw exception;
}But all I get is unreachable statement.Knotty_Boy wrote:
Ah that makes sense then, I'm a bit confused where I'm meant to put the code then, I'm carrying out 4 different operations on the fractions (add, subtract, multiply, divide) I need to ensure that the denom isn't a 0, so would I be best creating a method that tests for a zero Yes. Follow the DRY principle: Don't Repeat Yourself. If you find yourself writing the same code in several places, put that code into a method.
and then calling that at the end of each of the 4 operations and then throwing an exception if the answer is incorrect?No. Why would you do it at the end? You have to do it at the beginning. When you return, the method ends, and nothing after the return statement is executed. That's why you get that exception, as people have been explaining.
When you go to the cash machine, and ask for $50,000, does it first spit out the money, and then tell you "Insufficient funds"? If so, please tell me where you bank! -
Anyone know what this system stat means cell physical IO interconnect bytes
Hi All.
I can't find any documentation about "cell physical IO interconnect bytes" system stat - does anyone know what it signifies ?
Thanks
Dave
Class Name Value
64 cell physical IO interconnect bytes 1.160476804096E12
1 session logical reads 1.4572587197E10
8 free buffer requested 1.800353E8
1 CPU used by this session 1.8441013E7
8 hot buffers moved to head of LRU 9597137
8 physical write total IO requests 5319164
2 redo ordering marks 5082070
128 background timeouts 2907194
128 messages received 1752295
128 messages sent 17522461* select name, value from gv$sysstat where name like '%physical IO%'
SQL> /
NAME VALUE
cell physical IO interconnect bytes 983887872
cell physical IO bytes saved during optimized file creation 0
cell physical IO bytes saved during optimized RMAN file restore 0
cell physical IO bytes eligible for predicate offload 0
cell physical IO bytes saved by storage index 0
cell physical IO interconnect bytes returned by smart scan 0
cell simulated physical IO bytes eligible for predicate offload 0
cell simulated physical IO bytes returned by predicate offload 0
8 rows selected.
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production -
What does this statement mean:
I am having trouble downloading and installing iTunes to my laptop. Once iTunes is installed and I plug my Iphone into my laptop I get the following message: "The iTunes Library.itl file cannot be found or created. The default location for this file is in the "iTunes" folder in the "Music" folder."
I have uninstalled and reinstalled several times and I still can get it to work. The iTunes folder is there but when I try and open it I get the message above. Can someone help or have any of you had this message come up when you installed iTunes?
Thanks for the help of any kind.
Hines25It could be that there is a corrupt iTunes Library.itl file that iTunes is not managing to either open or remove. If this is to be a fresh install of iTunes you could delete the library file if it is there.
Repair Permissions
Right-click on the iTunes folder in "User's Music" and click Properties, then go to the Security tab and click Advanced. If necessary grant your account and system full control to this folder, subfolders and files, then tick the option to replace permissions on child objects which will repair permissions throughout the library. This is the XP dialog but Windows 7 shouldn't be too different.
If you had a previously working library on this laptop then try this...
Empty/corrupt library after upgrade/crash
Hopefully it's not been too long since you last upgraded iTunes, in fact if you get an empty/incomplete library immediately after upgrading then with the following steps you shouldn't lose a thing or need to do any further housekeeping. In the Previous iTunes Libraries folder should be a number of dated iTunes Library files. Take the most recent of these and copy it into the iTunes folder. Rename iTunes Library.itl as iTunes Library (Corrupt).itl and then rename the restored file as iTunes Library.itl. Start iTunes. Should all be good, bar any recent additions to or deletions from your library.
See iTunes Folder Watch for a tool to catch up with any changes since the backup file was created.
When you get it all working make a backup!
tt2
tt2
Maybe you are looking for
-
How to include the simbol % in a flash chart
hello everyone Do you know how to include the simbol % in a flash chart? I am using a 3D flash chart. This simbol obviously would be after that number of percentage. Do I must modify the chart XML adding some after that {VALUE} ? Any help would be ve
-
Help! Table not shown in browser!!!!!!
I never had this problem. The JTable is not shown at all!!! The JTable is embedded in an applet. I had similar program done (posted the code here) for another dataset and it works perfectly well. I'm suspecting the renderers. Here is the relevant cod
-
Time Stamp on MAXL Export File
I use MAXL to export data from our Essbase cube. Is there a way to add a time stamp to the filename?
-
Problem with the bone tool in FLash CS4
I cannot get this bone to connect with the lower part of the leg. I am doing a standard rough draft character walking. please help me p.s. if you have a vid or solution please post it in the topic ^_^ http://www.youtube.com/watch?v=TX8lDhbT7ig I post
-
When you get Gamecenter for this can u watch live games(NHL)
i was just wondering that once you get the nhl game center app and you watch live games?