Chrome Extension

Add foreign key in existing table Mysql

ALTER TABLE 
ContactDetails 
ADD 
EmployeeId INT UNSIGNED NOT NULL;

ALTER TABLE 
ContactDetails 
ADD 
CONSTRAINT fk_EMP_CONTACT FOREIGN KEY (EmployeeId) REFERENCES Employee(Id);
We are a bunch of lazy programmers so we developed this chrome extension
search code from your favorite search engine
Install Now

You can use the above queries to add foreign key constraints to an existing table. In the code snippet, we are assigning 'EmployeeId'  as a foreign key in 'ContactDetails' table.

Was this helpful?
0 Comments
Open Code Manager We are hiring