I have a database containing 5 tables. I have 2 tables with foreign key but no primary key does it work or not?
Printable View
I have a database containing 5 tables. I have 2 tables with foreign key but no primary key does it work or not?
a foreign key is a referential constraint between two tables. The foreign key identifies a column or a set of columns in one (referencing) table that refers to a column or set of columns in another (referenced) table. The columns in the referencing table must form a primary key or unique key in the referenced table
If referenced table contains unique key and referencing table referes that (unique key) key then it works
simple example
create table emp (
empno number ,
deptno number references emp15(empno), -- references itself
empname varchar2(20),
CONSTRAINT key_unique UNIQUE(empno)
)
Yah it can work
[QUOTE=susarlasireesha;23897]a foreign key is a referential constraint between two tables. The foreign key identifies a column or a set of columns in one (referencing) table that refers to a column or set of columns in another (referenced) table. The columns in the referencing table must form a primary key or unique key in the referenced table
If referenced table contains unique key and referencing table referes that (unique key) key then it works
simple example
create table emp (
empno number ,
deptno number references emp15(empno), -- references itself
empname varchar2(20),
CONSTRAINT key_unique UNIQUE(empno)
)[/QUOTE]
In above post pls change emp15 as emp
create table emp (
empno number ,
deptno number references emp(empno), -- references itself
empname varchar2(20),
CONSTRAINT key_unique UNIQUE(empno)
)