|
|
Re: Tbale with more than 2 foreign keys referencing to tables [message #429163 is a reply to message #429158] |
Mon, 02 November 2009 06:27 |
prachij593
Messages: 266 Registered: May 2009
|
Senior Member |
|
|
Sir,
Below is the my design script.
CREATE TABLE EMPLOYEE
( EMP_ID VARCHAR2(8) PRIMARY KEY,
ACC_ID VARCHAR2(6) ,
FIRST_NAME VARCHAR2(30) NOT NULL,
LAST_NAME VARCHAR2(30) NOT NULL,
SEX CHAR(1) NOT NULL,
REMARKS VARCHAR2(50),
)
/
CREATE TABLE EMPLOYEE_INFO
( EMP_ID VARCHAR2(8) NOT NULL,
DESIG VARCHAR2(3) NOT NULL,
EMP_JOIN_DATE DATE NOT NULL,
EMP_LAST_DATE DATE NOT NULL,
SALARY NUMBER(9),
REMARKS VARCHAR2(30),
FOREIGN KEY (EMP_ID)
REFERENCES EMPLOYEE(EMP_ID))
/
ALTER TABLE EMPLOYEE_INFO
ADD CONSTRAINT PK_EMPLOYEE_INFO
PRIMARY KEY (EMP_ID,DESIG,EMP_JOIN_DATE)
/
CREATE TABLE EMP_CONTACT_DETAILS
( EMP_ID VARCHAR2(8) PRIMARY KEY,
CURR_ADD VARCHAR2(100) NOT NULL,
PERM_ADD VARCHAR2(100) NOT NULL,
CONTACT_NBR VARCHAR2(15),
PAN_NBR VARCHAR2(15),
UPDATE_TMS TIMESTAMP(6) NOT NULL,
FOREIGN KEY (EMP_ID)
REFERENCES EMPLOYEE(EMP_ID))
/
CREATE TABLE SKILLS
( SKILL_ID NUMBER(3) PRIMARY KEY,
SKILL_NAME VARCHAR2(25) NOT NULL
)
/
CREATE TABLE EMPLOYEE_SKILLS
( EMP_ID VARCHAR2(8) NOT NULL,
SKILL_ID NUMBER(3) NOT NULL,
FOREIGN KEY (EMP_ID)
REFERENCES EMPLOYEE(EMP_ID),
FOREIGN KEY (SKILL_ID)
REFERENCES SKILLS(SKILL_ID))
/
ALTER TABLE EMPLOYEE_SKILLS
ADD CONSTRAINT PK_EMPLOYEE_SKILLS
PRIMARY KEY (EMP_ID,SKILL_ID )
/
CREATE TABLE APPLICATION1(
APPLICATION_ID VARCHAR2(10) PRIMARY KEY,
APPLICATION_NAME VARCHAR2(20),
)
/
CREATE TABLE TRAINING
( TRAINING_ID NUMBER(5) PRIMARY KEY,
TRAINING_NAME VARCHAR2(30) NOT NULL,
APPLICATION_ID VARCHAR2(10),
FLAG CHAR(1),
FOREIGN KEY (APPLICATION_ID)
REFERENCES APPLICATION1(APPLICATION_ID))
/
|
|
|