2 Replies Last post: Feb 1, 2010 12:15 PM by David Birmingham  
siddavp   13 posts since
Sep 18, 2009
Currently Being Moderated

Feb 1, 2010 11:53 AM

foriegn key

all

 

I am trying to enforce primary key and foriegn key relationship, I would want my sql should fail if there is no primary key , based on documentation I understand you can not enforce the priamy key check

is that true?

 

this is what Iam trying

CREATE TABLE TEST_PK
(POLICY_NB INTEGER CONSTRAINT PK_POLICY_NB PRIMARY KEY )

 

 

INSERT INTO TEST_PK VALUES (1234)

 

CREATE TABLE TEST_FK
(FK_POLICY_NB INTEGER
,POLICY_NB INTEGER
,
FOREIGN KEY (POLICY_NB)
  REFERENCES TEST_PK(POLICY_NB)
  MATCH FULL)

 

INSERT INTO TEST_FK VALUES (234,0);

 

but my insert is not giving any error?...

 

Thanks

Shawn Fox   391 posts since
Aug 15, 2006
Currently Being Moderated
1. Feb 1, 2010 12:13 PM in response to: siddavp
Re: foriegn key

Netezza is not an OLTP database, it is a data warehouse.  The data should already be cleaned and validated by your ETL process prior to loading into the target tables.  Generally the best practice is to first load your data into a set of staging tables and then run whatever validations you wish against the staging tables.  Once you have completed any validations and transformations, you then load the data into your target tables.

 

If you are trying to build an application which inserts data 1 row at a time and expects the database to automatically perform primary and foreign key constraint checks, then you need to run that application somewhere other than Netezza.  You can then write a process which pulls data out of that application database and pushes it into Netezza on a regular basis.

 

I don't know what you are trying to do, but the main thing to understand is that Netezza is not a general purpose database.  It is designed to load and query huge volumes of data, not to act as the backend database to accept data 1 row at a time from user forms, JMS, web services, etc.

David Birmingham   157 posts since
Sep 24, 2007
Currently Being Moderated
2. Feb 1, 2010 12:15 PM in response to: siddavp
Re: foriegn key

You don't want the SQL to fail if there is no key. You never want the SQL to fail on a target load. If it fails for any reason, it is not "load ready".

 

In bulk processing space, esp in Netezza, we have much power and freedom to make the final stream

"load-ready" and this would include any foreign key checks.

 

In ETL we would download the keys and check them before the load, peeling off any offenders.

In ELT we would likewise join the source and target tables and allow the missing keys to be our filter, peeling off any offenders.

 

But we don't want the SQL to do it- because this gets the SQL process involved in the row-by-row checking of data. In a bulk processing

model this is our undoing. We never want to check the data row-by-row, and in fact are unable to do it in Netezza because it is not a transactional

environment, and this theme carries to all corners of its architecture including row-by-row checks.

 

See the book Netezza Underground, and note rule #10 - never use the database for row-by-row data processing.

 

Think about what the common RDBMS database is doing when it throws an error for a failure like this - the row-by-row  overhead for the check is enormous, and the penalty for

recovery even more so. This is why in data warehousing, load operations are usually accompanied by a command to turn off constraints so that the load can go

faster. This means that the domain where the keys are checked is the same place where the rest of the data is made load-ready - in the function that is about to perform

the load.

 

So the short answer is - the lack of key checking in Netezza is what is practiced in data warehousing, and is exactly what we want an appliance to do.

More Like This

  • Retrieving data ...