I have 2 tables : userphone and cellphone.I need to add a foreign key (brand) but it keeps giving me the following error:
ORA-02270: no matching unique or primary key for this column-list
CREATE TABLE CELLPHONE (
NR NUMBER(12,0) PRIMARY KEY CHECK (NR LIKE '35566%' OR NR LIKE '35567%'),
CREATE TABLE USERPHONE (
NR_CLIENT NUMBER PRIMARY KEY,
NAME VARCHAR2(10) NOT NULL,
BRAND VARCHAR2 (10),
CONSTRAINT FK_BRAND FOREIGN KEY (BRAND) REFERENCES CELLPHONE (BRAND)
Read about foreign keys: http://www.w3schools.com/sql/sql_foreignkey.asp
A FOREIGN KEY in one table points to a PRIMARY KEY in another table.
Brand is not a primary key in your CELLPHONE table.
You could create a BRAND table to store your unique brands (with a primary key) and then create a foreign key in both tables referencing it.