Home » RDBMS Server » Server Administration » Primary key and Foreign key....
Primary key and Foreign key.... [message #371260] Mon, 25 September 2000 02:19 Go to next message
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 Go to previous messageGo to next message
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.
Re: Primary key and Foreign key.... [message #371262 is a reply to message #371261] Mon, 25 September 2000 03:13 Go to previous message
Samuel
Messages: 17
Registered: September 2000
Junior Member
Thanks a lot!
Previous Topic: cleaning phone-numbers column with explicit cursor
Next Topic: multiple commands in one access
Goto Forum:
  


Current Time: Tue Apr 16 12:14:55 CDT 2024