Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> ATTN: VSATYA RE:Help on Data Integrity Constraints ATTN: VSATYA
VSATYA,
Here is my solution to your Data integrity issues. I think you should in essence normalize your Master table to something
as described below....
Sample Data:
Master Table
Type Code Desc
AISTATUS A Active AISTATUS I InActive ROLE MGR Manager ROLE DIR Director ROLE SRMGR Senior Manager SEX M Male SEX F Female
I would break the Master Table into these three tables.
In this way you would only need a primary key constraint on CODE. I know you probably dont want to go breaking up that master table up but this will most likely save youn a lot of hassle in the future. Mainly in the ease you will have adding new values to the MasterRoles_table and not having any type of conflicts.
DIR Director MGR Manager
MasterSex_table;
Code Desc
M Male F Female MasterAISTATUS_table; Code Desc --------------------- A Active I Inactive ***********************************************
Now by having done this when you go to update Table A you will not need to add those extra columns.
Ex. Data
TableA
Emp_id EmpName Status Gender Designation
911 theDBA I M theDBA **Record not added Since 'theDBA' is not in ( SELECT desc FROM MasterRole_table)***
Ex:
TableName: TableA
columns:
EmpId Varchar2(5) EmpName varchar2(10) Status Varchar2(5) Gender Varchar2(5)
Foreign key on Status referencing MasterAISTATUS(Code) <---so long as the value is in the column it will be added Foreign key on Gender referencing MasterSex_table(Code) <---so long as the value is in the column it will be added Foreign key on Designation referencing MasterRoll_table(Desc) <---so long as the value is in the column it will be added
Original Post
Suppose I have a table "Master" with 3 fields
Table Name: "Master"
Columns:
Type Varchar2(10) Code Varchar2(5) Desc Varchar2(20)
Combination of Type & Code is the Primary key.
Let's say this table acts like master/setup data to different constants that will be used in the system.
Sample Data:
Type Code Desc
AISTATUS A Active AISTATUS I InActive ROLE MGR Manager ROLE DIR Director ROLE SRMGR Senior Manager SEX M Male SEX F Female
Values of the "Code" are used to store in other tables like below
Ex:
TableName: TableA
columns:
EmpId Varchar2(5) EmpName varchar2(10)
Which one of the below approachs is the best way to maintain
referential(data integrity) constraint between these two tables?
1. Use triggers to validate the data.
2. Add 3 more columns in this case to the table and add 3 foreign key
reference constraints to Master Table.
Updated TableA definition:
EmpId Varchar2(5) EmpName varchar2(10) StatusType varchar2(10) Status Varchar2(5) Foreign key on StatusType,Status referencing Master(Type,Code) GenderType varchar2(10) Gender Varchar2(5) Foreign key on GenderType,Gender referencing Master(Type,Code) Des_type Varchar2(10) Designation Varchar2(5) Foreign key on Des_type,Designation referencing Master(Type,Code)
Any ideas/help on this highly appreciated.
Thanks
--------------= Posted using GrabIt =----------------------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =- Received on Wed May 11 2005 - 21:12:05 CDT
![]() |
![]() |