To Constraint or NOT To Constraint
Hi,
I would appreciate if some body can throw light on following, possibly with some expert opinions - links;
Let me explain the scenario;
We have OLTP system which stores data in proprietory file system. We have extracts of data in flat file from that system every day.
We have created tables in oracle to store data from those flat files. Every night we transfer data from flat files to corresponding tables that matches with something called Clusters (don't confuse with oracle clusters!) of flat file. So you can say One cluster in Proprietory file system = 1 table in oracle db.
Now my question;
We have people who advocates that we should not put any constraints (especially PK/FK) on oracle tables as it will slow down the load process. Beside that, OLTP system does check all constraints. So we trust that system and data that is coming from there is correct!
I don't buy this explanation. My dilemma is; By putting constraints -especially PK/FK - will it really make loading of data that slow? We have oracle 10.1.0.3
Thanks in advance
Yes it is true that there will be overhead to enforce constraints on the data.
If your question is how much is directly proportional to the data.
In this scenario, you need to do analysis whether to enforce constraints are not.
If the flat files are populated from well established application where there is very less chance of integrity violation, you can make a decision of ignoring constraints. You are taking a chance of loosing some integrity.
In my last project we have production and replication environments. Both of them are running on Oracle. We use quest product, shareplex to replicate the data. Shareplex will replicate most of the DDLs on the tables, except creating constraints. It make sense as it is expecting that in production database integrity will be maintained.
If the underlying application which is using flat files is not good enough to maintain integrity, then it will be better to go with constraints.
You need to decide between integrity and performance as per your project requirements.
Similar Messages
-
I saw this posted on Metalinks and the answer was to be found here. I can't seem to find it..... has there been a resolution to this? Unfortunately, I am running into the same problem.
You help is appreciated.
I am trying to create Oracle8i schema from MS SQL Sercer 7.0 using Oracle Migration Workbench and it is not functioning as expected.
Problems are:
=============
1. If the column type is CHAR OR VARCHAR in MS SQL Server and the integrity contraints is NOT NULL or NULL, in Oracle8i it create as NULL only and it not taking the NOT NULL in MS SQL Server to Oracle8i NOT NULL. I can say that it is ignoring the integrity constraint for CHAR OR VARCHAR type while converting to Oracle8i.
Example in MS SQL Server
========================
CREATE TABLE emp (
emp_name CHAR(10) NOT NULL
the tool converts to Oracle8i as
CREATE TABLE emp (
emp_name CHAR(10)
It is ignoring the NOT NULL constraints in Oracle8i and it is happening only for CHAR and VARCHAR data type. Can anyone help me on this how to rectify the problem in Migration Workbench. ....... "We reported this for the EA's, but got little response and obviously no resolution.
K. -
NULLABLE column is not updated after the NOT NULL constraint definition...
Hi,
SQL> select column_name,nullable from all_tab_columns where table_name='EMP';
COLUMN_NAME NULLABLE
EMPNO N
ENAME Y
JOB Y
MGR Y
HIREDATE Y
SAL Y
COMM Y
DEPTNO Y
CODE_POLEIS_DIAM Y
9 rows selected
SQL> ALTER TABLE EMP add constraint emp_job_nn check(job is not null);
Table altered
SQL> select constraint_name from all_cons_columns
2 where table_name='EMP';
CONSTRAINT_NAME
FK_DEPTNO
PK_EMP
EMP_JOB_NN
SQL> select column_name,nullable from all_tab_columns where table_name='EMP';
COLUMN_NAME NULLABLE
EMPNO N
ENAME Y
JOB Y <---------'NULL'
MGR Y
HIREDATE Y
SAL Y
COMM Y
DEPTNO Y
CODE_POLEIS_DIAM Y
9 rows selected
Why is not updated....????
In Oracle ebook:
Oracle® Database Reference
10g Release 2 (10.2)
Part Number B14237-02
the comments about the NULLBLE column are as follows:
"Specifies whether a column allows NULLs. Value is N if there is a NOT NULL constraint on the column or if the column is part of a PRIMARY KEY. The constraint should be in an ENABLE VALIDATE state."
BUT BY DEFAULT ALL CONSTRAINTS ARE IN VALIDATE STATE
(Ref: Oracle® Database SQL Reference
10g Release 2 (10.2)
Part Number B14200-02 )Note : I use OraDB 10g v.2
Thanks a lot
SimHi,
Tom Kytes answer it before:
SQL> create table t ( id int );
Table created.
SQL> desc t
Name Null? Type
ID NUMBER(38)
SQL> alter table t add constraint t_nn check (id is not null);
Table altered.
SQL> insert into t (id) values (null);
insert into t (id) values (null)
ERROR at line 1:
ORA-02290: check constraint (TANDREWS.T_NN) violated
SQL> desc t
Name Null? Type
ID NUMBER(38)
Followup July 16, 2003 - 10am US/Eastern:
that is not a NOT NULL constraint, that is a check constraint
ops$tkyte@ORA920LAP> create table t ( x int );
Table created.
ops$tkyte@ORA920LAP> alter table t modify x not null;
Table altered.
ops$tkyte@ORA920LAP> set linesize 50
ops$tkyte@ORA920LAP> desc t
Name Null? Type
X NOT NULL NUMBER(38)To see the full thread in asktom, please refer to:
- http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1338402651192
Cheers,
Francisco Munoz Alvarez
http://www.oraclenz.com -
All_tab_columns says NULLABLE = 'Y' while there is a NOT NULL constraint
Hi all,
I created a table MANT (here is the script) :
CREATE TABLE DMI.MANT
MANT NUMBER(7) NOT NULL,
SPER NUMBER(7) NOT NULL,
RANT VARCHAR2(10 BYTE) NOT NULL,
ANT VARCHAR2(200 BYTE),
CMT VARCHAR2(800 BYTE),
PERIODE VARCHAR2(200 BYTE),
DU DATE,
USR VARCHAR2(10 BYTE),
DTE DATE
)Then I added a column called RSMF :
ALTER TABLE DMI.MANT
ADD (RSMF VARCHAR2(100 BYTE));and added a check constraint :
ALTER TABLE DMI.MANT ADD
CONSTRAINT RSMF_NOT_NULL
CHECK (RSMF IS NOT NULL)
ENABLE
NOVALIDATEI had to add NOVALIDATE clause because all the records had a null value. So to validate the constraint I simply executed the following update
update dmi.mant set rsmf = 'yy';and then validate the contraint with :
ALTER TABLE DMI.MANT
MODIFY CONSTRAINT RSMF_NOT_NULL
VALIDATE;The problem comes when I query ALL_TAB_COLUMNS table...
Select OWNER,TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_LENGTH,NULLABLE
from all_tab_columns
where table_name = 'MANT'
and owner = 'DMI'
and COLUMN_NAME = 'RSMF';Why does the ALL_TAB_COLUMNS table gives for RSMF column a NULLABLE value equals to 'Y' while there is a validated check NOT NULL constraint on it ?
It's annoying because I want to get all the NOT NULL columns in a given table and here the SRMF column is not returned...
Here is the result :
OWNER |TABLE_NAME |COLUMN_NAME |DATA_TYPE |DATA_LENGTH |NULLABLE
DMI |MANT |RSMF |VARCHAR2 |100 |YThks for your replies...NULLABLE would be true if you created the table like this:
create table x (a not null)
but not if you add a check constraint after the fact. -
Issue in adding not null constraint on 250 G table with 50 million rows.
Guys,
I need to add not null constraint on 2 column of a table with 50 million rows and ~250 GB in size, These 2 columns are newly added and I have also update the value for each of these columns to not null for each row.
After that I am adding not null constraint on these 2 columns this is taking 1 hour to complete, Is there any way to speed up this, I don't want to use ENABLE NOVALIDATE option or rather I can't use that option.user445775 wrote:
Guys,
I need to add not null constraint on 2 column of a table with 50 million rows and ~250 GB in size, These 2 columns are newly added and I have also update the value for each of these columns to not null for each row.
After that I am adding not null constraint on these 2 columns this is taking 1 hour to complete, Is there any way to speed up this, I don't want to use ENABLE NOVALIDATE option or rather I can't use that option.And what's wrong with it taking an hour? Presumably, this is a one time operation, and it doesn't really interfere with anything else. -
How to create a named not null constraint
Hi All,
How to create a table with a named not null constraint?
and how to add a named not null constraint to a table?
Thanks for the help.Hi,
I guess you are asking for a column inside a table, having a named not null constraint. Am I correct? Try the following.
SQL> create table checktab (col1 varchar2(30) constraint NN_const not null);Is this what you required?
Please post technical questions in respective forums.
Hope that helps.
Savitha. -
ORA-02253: constraint specification not allowed here
I'm trying to create a table clients with primairy key, but I'm getting the error "ORA-02253: constraint specification not allowed here"
if anyone call what to do
CREATE TABLE CLIENTS
NUMERO NUMBER(6) CONSTRAINT PK_CLIENTS PRIMAIRY KEY,
NOM VARCHAR(63), NOT NULL,
PRENOM VARCHAR(63),
NAISSANCE DATE
Edited by: user10397656 on Oct 13, 2008 1:40 AMThere are some errors in your script :
PK_CLIENTS PRIMAIRY KEY
and
NOM VARCHAR(63)*,* NOT NULL,
Try this way
CREATE TABLE CLIENTS
NUMERO NUMBER(6) CONSTRAINT PK_CLIENTS PRIMARY KEY,
NOM VARCHAR(63) NOT NULL,
PRENOM VARCHAR(63),
NAISSANCE DATE
); -
How to temporarily disable on delete cascade but not the constraint
Hi all
i would like to know if this is possible
how to temporarily disable on delete cascade but not the constraint
i want to delete a row from the primary key table but i dont want the data from the foreign key to be deleted even though there is an on delete cascade set.
how do i temporarily disable on delete cascade from firing without disabling the constraint
RgrdsThere is an option which I've never used before but just read about which is to create your foreign key constraint as on delete SET NULL
instead of on delete cascade.
This will allow you to delete a parent and will set the foreign key column values in the child table to nulls
e.g.
SQL> create table parent (father varchar2(30) primary key,
2 age number);
Table created.
SQL>
SQL> create table child (father varchar2(30) constraint fk references parent(father) on delete set null,
2 child varchar2(30),
3 age number);
Table created.
SQL>
SQL> insert into parent values ('JOHN', 34);
1 row created.
SQL> insert into child values ('JOHN', 'SARAH', 10);
1 row created.
SQL> insert into child values ('JOHN', 'BILL', 12);
1 row created.
SQL>
SQL> commit;
Commit complete.
SQL>
SQL> delete from parent where father = 'JOHN';
1 row deleted.
SQL>
SQL> select * from child;
FATHER CHILD AGE
SARAH 10
BILL 12
SQL> HTH AMM -
To create referential constraints or not while designing a data model...
Hi,
If I were to design a data model involving some tables which tend to grow fast and huge, which option w.r.t creating referential constraints (foreign key constraints) between tables is advisable - to create or not to create?
Assuming that there are no specific requirements to implement referential integrity (though it maybe implicity stated). I know that creating referential constraints might maintain data integrity but on the other hand, it might be a bottleneck in some data-intensive queries/operations involving huge tables.
In other words, what factors should we consider while deciding on to create referential constraints or not in a data model?
thanks & regds,
Ashok.Hi,
>>it might be a bottleneck in some data-intensive queries/operations involving huge tables.
Hummm, are you sure ? I'm not convinced that foreign key constraints can cause a bottlenecks while querying the database. Why ? Otherwise, DML statements can be affected by some constraints and indexes ... in some systems for example perform data loading in a Data Warehouse, DSS Systems, etc....
"The key thing to remember here is that if you cannot guarantee the integrity of your data, it doesn't matter how fast you can retrieve it from the database"
Cheers -
Difference between Primary Key and Unique Key with NOT NULL constraint
As both can be referred to another table.
Apart from the difference that Primary Key can be only 1 and Unique keys can be multiple,
is there any difference?
Like in terms of type of Index?PARAG_C wrote:
As both can be referred to another table.
Apart from the difference that Primary Key can be only 1 and Unique keys can be multiple,
is there any difference?
Like in terms of type of Index?Technically there is almost no difference. Logically the two are often used for slightly different concepts.
The PK (and with it the index) is often an ID column filled by a seqeunce. This key can then be refenced by foreign key constraints on other tables. it is very useful to have this as a meaningless technical construct. Because then the chance that such a ID needs to be changed is extremly slim.
The UK (and with it the index) is often one or several columns that represent the logical key for the entity. Foreign key constriants should not point to this. THe chance that this attribute will be changed at some point in time is way higher then for a meaningless number (ID). -
Constraints are not created when using a cart
Hi all,
I have created a cart in SQL Developer with all the tables from HR schema. If I apply the cart to my database cloud service the tables and data are there but most of the constraints are missing.
In log I can see error messages like:
Error starting at line 5 in command:
ALTER TABLE "EMPLOYEES" ADD CONSTRAINT "EMP_DEPT_FK" FOREIGN KEY ("DEPARTMENT_ID")
REFERENCES "DEPARTMENTS" ("DEPARTMENT_ID") ENABLE
Error report:
SQL Error: ORA-02270: no matching unique or primary key for this column-list
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view
Primary key constraints are completely missing in the log.
I have tried it with option "Disable constraints before loading data" checked and unchecked.
How can I transfer the schema (tables, data, constraints) to my cloud service. I don't want to create the constraints manually because I have a web service which is based on the exact structure of HR schema in my local database.
Kind regards
JuergenYou should actually look at the headers first, IMO. Not knowing "what is going on in there" is a very bad reason to discard that solution. The Content-Type header is meant to indicate exactly the type of content you are getting (your want the text/html mime-type).
Not all servers report the correct content type all the time in this header so it won't be a 100% solution.
BTW, the Aperture project is specifically intented to extract content and metadata from various sources, including websites. You might be able to use that. -
SQL Developer 2.1.0.63.73 not displaying constraint violation on commit
I've found an odd case where SQL Developer (2.1.0.63.73) is not displaying an error message on a constraint violation.
CREATE TABLE tmp1 ( id NUMBER, val NUMBER );
CREATE MATERIALIZED VIEW tmp2 REFRESH ON COMMIT AS
SELECT id, SUM(val) AS total FROM tmp1 GROUP BY id;
ALTER TABLE tmp2 ADD CONSTRAINT ck_tmp1 CHECK (total <= 100);
INSERT INTO tmp1 (id, val) VALUES (1, 75);
INSERT INTO tmp1 (id, val) VALUES (1, 25);
INSERT INTO tmp1 (id, val) VALUES (1, 10);
commit;
In SQL Developer I get:
CREATE TABLE succeeded.
CREATE MATERIALIZED succeeded.
ALTER TABLE tmp2 succeeded.
1 rows inserted
1 rows inserted
1 rows inserted
commited
Doing the inserts in SQLPlus, however, gives me the expected output:
SQL> INSERT INTO tmp1 (id, val) VALUES (1, 75);
1 row created.
SQL> INSERT INTO tmp1 (id, val) VALUES (1, 25);
1 row created.
SQL> INSERT INTO tmp1 (id, val) VALUES (1, 10);
1 row created.
SQL> commit;
commit
ERROR at line 1:
ORA-12008: error in materialized view refresh path
ORA-02290: check constraint (PROJECT.CK_TMP1) violated
Is this a bug in SQL Developer?
Edited by: eaolson on Jan 20, 2010 2:50 PMSimilar symptom with SQL Developer 2.1.0.63.73 and now 2.1.1.64. I know how absurd it sounds, but it's definitely happening and I don't know what to do... This must be a bug in SQL Developer!
Script:*
select id, author_id_oid from project where prj_nr = 'xy' ;
delete from project where prj_nr = '0908001' ;
select id, author_id_oid from project where prj_nr = 'xy' ;
commit;
select id, author_id_oid from project where prj_nr = 'xy' ;
SQL Developer output:*
ID AUTHOR_ID_OID 735 50
1 rows deleted
ID AUTHOR_ID_OID
commited
ID AUTHOR_ID_OID
735 50>
TOAD output:*
>
ID AUTHOR_ID_OID
735 50
1 row selected.
1 row deleted.
no rows selected.
commit
Error at line 7
ORA-02091: transaction rolled back
ORA-02292: integrity constraint (RD.PROJECTEDSAV_FK1) violated - child record found
ID AUTHOR_ID_OID
735 50
1 row selected.>
SQuirreL SQL:*
ID AUTHOR_ID_OID735 50
Query 1 of 1 elapsed time (seconds) - Total: 0.08, SQL query: 0.07, Building output: 0.01
1 Row(s) Deleted
Query 1 of 1 elapsed time (seconds) - Total: 0.06, SQL query: 0.06, Building output: 0
ID AUTHOR_ID_OID
Query 1 of 1 elapsed time (seconds) - Total: 0.09, SQL query: 0.06, Building output: 0.03
Error: ORA-02091: transaction rolled back
ORA-02292: integrity constraint (RD.PROJECTEDSAV_FK1) violated - child record found
SQLState: 40000
ErrorCode: 2091
Position: 6
ID AUTHOR_ID_OID
735 50
Query 1 of 1 elapsed time (seconds) - Total: 0.13, SQL query: 0.06, Building output: 0.07>
Thanks in advance for any suggestion!
Edited by: Victor Ott on Mar 20, 2010 2:33 AM -
Unique constraint is not thrown when used MERGE INSERT (alone) via dblink.
We found some interesting behaviour of unique constraint on Merge query when we use Merge When Not Matched Insert (no update query) via a dblink.
In one Schema S1, on Table A1(c1,c2,c3) there is a unique constraint on column (c1,c2).
Column c2 is nullable and has null for some records.
Now i have a table A2 with same defintion as A1 in Schema S2.In S2 , i have a dblink of S1 as S1 itself.
I have data in S2.A2. Here also i have some records with c2 as null and c1 matching with the data of S1.A1.
Now from schema S2,
I am using the following Merge Query,
MERGE INTO S1.A1 target
USING S2.A2 source
ON (target.c1 = source.c1 and target.c2 = source.c2)
WHEN NOT MATCHED
INSERT (c1,c2,c3) values (source.c1, source.c2,source.c3)
WHEN MATCHED
UPDATE c3 = source.c3;
Now when i execute this merge in schema S2,
if i have some data in S1.A1 and S2.A2 having c1 as same and c2 as null, as oracle does not treat two nulls same, it goes for an insert, i have got unique constraint violated error.
But if i execute MERGE INSERT alone, though that record is getting inserted , i am not getting unique constraint violated error.
Oracle version we are using is 10g (10.2...).
Is it a bug in oracle or what could have caused this behaviour.Dear,
ERROR at line 1:
ORA-00001: unique constraint (SYS_C00137508) violatedYou need to think about two things
(a) read consistency : what was the situation of table_1 when the maching clause has been initially evaluated ; there were 0 rows matching which means the merge operation will be all insert
(b) your matching clause has a problem : the join column must be unique in both tables otherwise the merge will be ambigous. You don't have a unique key on the source table
(c) think that the merge operation will never insert id =1 and then update id = 1 within the same operation. This will never happen
Hope this helps
Mohamed Houri -
Use domain constraint does not generate a constraint name
Hello,
I am using a domain for which I specified a check constraint. In the naming standard template I defined a template for the column check constraint.
Now, if I am modelling a table in the relational model (not derived from logical model) and specify a column with the given domain, having checked "Use Domain Constraints" I will not get a named check constraint generated. The check constraint is generated in the DDL as inline check constraint.
Any hint, or who does the template for the column check constraint work?
Thanks in advance,
puchtec
Operating System: Windows XP 32-bit
Product Version: 2.0.0.584Hello puchtec,
In the naming standard template I defined a template for the column check constraintyou also need to apply templates - you can do it for one table in table dialog or for whole relational model - use pop-up menu for relational model in browser.
Philip -
How to create business rule for 'Integrity constraint - child not found'
Hello, I am using JDeveloper 11.1.2.3.0.
When an integrity constraint is violated an error message coming from database is displayed in my application. In this case is the error "integrity constraint (TableName) violated - child record found "
How can I personalize the error shown in this case? I tried with EO business rules but I couldn't find this key, only "Key exists" or "UniqueKey".
Can anyone help?Check Catch Me If You Can article. This should be handled there as one of the errors thrown in the model layer. Check the AdfmErrorHandlerImpl ...
Timo
Maybe you are looking for
-
Hi Team We are facing a strange issue in CC BPM. For some of the messages, one send step in BPM remains in "InProcess' status for a long time ( more than 2 hours) When I try to find out the problem , I see this message in SWWL Work item 000000189474
-
hi how do i remove a device from my account? i use to have a blackberry phone but i dont anymore i have a playbook now.. since i dont have the phone i want it taken off my account..no point of having it if i dont have the phone.. plz help thx..
-
Map entries of a table on several 0..1 nodes
Hello Gurus!! I have to map the next structures, I hope somebody could guide me. Source <FIELDS> 0..2 <NAME> <VALUE> </FIELDS> Target <DATA> 0..1 <NAME1> <VALUE1> <NAME2> <VALUE2> <DATA> An example could be: Source <FIELDS> <NAME>COLOUR</NAME>
-
Missing data during calculation
Hi guys, I have problem in calculation: ELSEIF(@ISUDA("Produkt","PRD_TAB")) IF("Minimalny stan zapasów (tys. tabletek)" < 0 OR "Minimalny stan zapasów (tys. tabletek)" == #Missing) "Minimalny stan zapasów (tys. tabletek)" = 0; ENDIF IF("Seria minimal
-
I'm interested in the idea of maybe having a sticky thread in this forum for all the Linux gamers out there. Specifically older Loki games such as Myth2 and Alpha Centauri. One reason, being a avid Linux gamer. I find it difficult to Google for infor