Reputation: 19
I have two tables Cal and EEL I want to use the primary key of cal that is Cal_id as the foreign key for EEl
Here's what I tried.
Create table ELL
(course_code varcahr2(10) Constraints pk_course_code Primary Key,
Course_Title varchar2(30),
cal2_idnumber not null,
Constraint fk_cal2 Foreign Key (cal_id) References cal_id(cal2_id)
)
but it shows error at line 6 Ora-00904 "Cal_ID" invalid character
can someone tell me how to do this
Upvotes: 0
Views: 24409
Reputation: 29
Constraint fk_cal_id2 Foreign Key (cal2_id) References cal(cal_id) ----------- constraint name (col in EEL) parent table name(parent table column name)
Upvotes: 0
Reputation: 1
References cal_id(cal2_id)
-- call_id
is not your table name.
Instead of above code you can use as below.
References parent_table_name(cal2_id)
Upvotes: 0
Reputation: 2229
ALTER TABLE table_name
add CONSTRAINT constraint_name
FOREIGN KEY (column1, column2, ... column_n)
REFERENCES parent_table (column1, column2, ... column_n);
Upvotes: 4
Reputation: 637
Not difficult, here below an example:
CREATE TABLE supplier
( supplier_id numeric(10) not null,
supplier_name varchar2(50) not null,
contact_name varchar2(50),
CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
);
CREATE TABLE products
( product_id numeric(10) not null,
supplier_id numeric(10) not null,
CONSTRAINT fk_supplier
FOREIGN KEY (supplier_id)
REFERENCES supplier(supplier_id)
);
Upvotes: 0