Is this a good practice to make a one to one relation table in mysql? -


mysql dbms used

i have created customer table

create table customer (id int , name varchar(3), primary key(id)); 

now make table address making unique foreign key (id )from customer table

create table customer_add (hno int , block_name varchar(3), street_no int, town varchar(20), state varchar(20), cust_id int unique, primary key(hno), foreign key(cust_id) references winecustomer(id)); 

is wrong method ?if yes how should make 1 one relation? there relation other onetoone ,onetomany,manytomany?

based off erd (entity relationship diagram), there can 1 1 relationships. when create table choose 1 gets primary key of other table , therefore becomes foreign key. in erd can determine 1 should have other tables primary key seeing 1 has total/full participation.

example: employee ---1----- (has) ----1--- (manager)

here 1 employee has 1 manager, , manager has 1 employee. lets employee has employee_ssn attribute inside manager table can take employee_ssn foreign key refers employee table. or, lets manager has m_ssn, employee takes m_ssn foreign key refers manager table. if 1 of them had full/total participation, 1 receive primary key of other table. totally okay have 1 1 relationships, (a 1 1, relationship easier , clearer see in erd).


Comments