Home » RDBMS Server » Server Administration » How I can to create foreing and primary keys?
How I can to create foreing and primary keys? [message #371293] Fri, 29 September 2000 05:45 Go to next message
Samuel
Messages: 17
Registered: September 2000
Junior Member
Hi,
I must to create on Oracle the primary keys, the foreign keys and the relationship between tables?
How can I do?
Write me the query, please.
Re: How I can to create foreing and primary keys? [message #371298 is a reply to message #371293] Sat, 30 September 2000 00:16 Go to previous message
Rajendra
Messages: 23
Registered: September 2000
Junior Member
pls try this..
suppose u have client table, u can set primary key by the sql code like this-
create table client(
cl_code number(7) constraint cl_prim primary key,
cl_grp char(2) not null,
cl_name char(50) not null,
cl_add1 char(40) not null,
cl_city char(20) not null,
cl_pin char(6) not null,
cl_tel char(20),
cl_fax char(20))

suppose 2nd table is bill, then u can set the foreign key by this code-
CREATE TABLE BILL(
BILL_NO NUMBER(7) PRIMARY KEY,
CL_CODE NUMBER(7) NOT NULL,
BL_DETAIL VARCHAR2(200) NOT NULL,
RATE_DET VARCHAR2(100),
BILL_AMT NUMBER(10,2) NOT NULL,
AMT_ADJ NUMBER(10,2),
CONSTRAINT fkey1 FOREIGN KEY (CL_CODE) REFERENCES CLIENT(CL_CODE))

Now you can issue the sql for extracting the values from the 2 tables -
select a.cl_name,a.cl_code,b.* from client a,bill b where a.cl_code=b.cl_code;

regards....
Rajendra
Previous Topic: SQL*Plus 3.3 vs. SQL*Plus8.0
Next Topic: Oracle 8i & Sun Solaris Install
Goto Forum:
  


Current Time: Tue Apr 23 11:52:53 CDT 2024