Primary key and Foreign key.... [message #371260] |
Mon, 25 September 2000 02:19 |
Samuel
Messages: 17 Registered: September 2000
|
Junior Member |
|
|
Hi,
I have a problem! I must to create two tables. How I do to create the Primary Key, the Foreign Key and the relationship?
It' s very important for my work.....
Thank you.
|
|
|
Re: Primary key and Foreign key.... [message #371261 is a reply to message #371260] |
Mon, 25 September 2000 02:46 |
Thierry Van der Auwera
Messages: 44 Registered: January 2000
|
Member |
|
|
Halo Samuel,
Hereby a small example. Hope this helps.
CREATE TABLE tab1 (
id NUMBER(38) NOT NULL,
code VARCHAR2(10) NOT NULL,
txt VARCHAR2(40)
)
PCTFREE 10
TABLESPACE tablesp_data
STORAGE (INITIAL 50000 NEXT 50000 PCTINCREASE 0)
;
CREATE TABLE tab2 (
id NUMBER(38) NOT NULL,
code VARCHAR2(10) NOT NULL,
tab1_id NUMBER(38),
txt VARCHAR2(40)
)
PCTFREE 10
TABLESPACE tablesp1
STORAGE (INITIAL 50000 NEXT 50000 PCTINCREASE 0)
;
ALTER TABLE tab1 ADD (
CONSTRAINT tab1_PK PRIMARY KEY (ID)
USING INDEX
PCTFREE 10
TABLESPACE tablespc_index
STORAGE (INITIAL 50000 NEXT 50000 PCTINCREASE 0)
)
;
ALTER TABLE tab2 ADD CONSTRAINT tab2_tab1_fk1
FOREIGN KEY (tab1_id)
REFERENCES tab1 (id) ;
Greetings,
Thierry.
|
|
|
|