Saturday, 20 February 2016

How to Add a Foreign Key to MySQLIn Feburary 2016 20,

In Feburary 2016 20,
Click the Windows 'Start' button and click 'All Programs.' Click 'MySQL' and then click 'MySQL Workbench' to open your main console.
Click 'Edit SQL Script' in the main console window. This opens a SQL editor where you create the foreign key.
Type the following code into your editor:alter table table_name add constraint key_name foreign keyreferences tbl_name primary_keyThe first line sets the foreign key. Replace 'table_name' with the name of your table. 'Key_name' is the name of the column in your table you want to set as the foreign key. The second line is the primary key information to link to the foreign key. Replace 'tbl_name' with the table that contains the primary key and 'primary_key' with the primary key column name.
Click 'Run' to run your SQL statement. The foreign key is created, and your tables are set up with the linked attributes.
In Feburary 2016 20,

No comments:

Post a Comment