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
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