Tuesday, 23 April 2013

Create foreign key in mysql

How to create Foreign Key in MySQL

create table tblstate
(
id int primary key auto_increment not null,
countryid int ,
statename varchar(20),
foreign key(countryid) references tblcountry(id)
)


OR


ALTER TABLE tblstate ADD CONSTRAINT countryid_ref FOREIGN KEY (countryid) REFERENCES tblcountry (id);

No comments:

Post a Comment