MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Referential Constraint

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Tue Jan 10, 2006 6:12 pm    Post subject: Referential Constraint Reply with quote

I've looked the doc and still I still don't understand. Here is what I need:
Code:

Table 1 contains Departments
Primary key is Departments

Table 2 contains Employee and Dept
Primary key is Employee
Foreign key is Dept
References Table1 (Departments)
on Delete  ?????


My requirements are:
Table1 will not allow a delete if a row exist in Table 2.
Table2 will not allow an Insert/Update if not in Table1.
Table2 can Delete a row.

This is almost a copy of the IBM doc, I don't understand the 'On Delete' references.
_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Jan 11, 2006 5:10 am    Post subject: Reply with quote

NASCAR9,

You should have on delete RESTRICT and also you need to self referencing table to implement rule # 1

Check this link which might you give you a better idea

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/1.6.2?SHELF=&DT=20010718164132&CASE=

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Wed Jan 11, 2006 11:05 am    Post subject: Reply with quote

So here is how I think it should be coded.

Code:

                                               
ALL TABLESPACES HAVE BEEN CREATED.             
                                               
                                               
CREATE TABLE FDBMD.TABLE1                     
    (DEPARTMENT       CHAR(25)       NOT NULL,
      PRIMARY KEY (DEPARTMENT))               
       IN FDBMD.FTSCLMM1                       
       ;                                       
                                               
CREATE UNIQUE INDEX FDBMD.XTABLE1             
       ON FDBMD.TABLE1                         
      (DEPARTMENT)                               
       USING STOGROUP FSGALLT                 
       PRIQTY 450                             
       SECQTY 225                             
       BUFFERPOOL BP11                         
       CLOSE NO; 
                             
                                               
CREATE TABLE FDBMD.TABLE2                     
    (EMPLOYEE         INTERGER       NOT NULL,
     DEPT             CHAR(25)       NOT NULL,
      PRIMARY KEY (EMPLOYEE)                   
       FOREIGN KEY (DEPT)                     
        REFERENCES TABLE1 (DEPARTMENT)         
        ON DELETE RESTRICT                     
       IN FDBMD.FTSCLMM2                       
       ;

                                     
CREATE UNIQUE INDEX FDBMD.XTABLE2 
       ON FDBMD.TABLE1             
      (EMPLOYEE)                   
       USING STOGROUP FSGALLT     
       PRIQTY 450                 
       SECQTY 225                 
       BUFFERPOOL BP11             
       CLOSE NO;                   
                                   
ALTER TABLE TABLE1                 
    FOREIGN KEY (DEPARTMENT)       
    REFERENCES TABLE2 (DEPT)       
        ON DELETE RESTRICT;       


_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group