Jump to content

Problem adding Foreign Key in a table


Xenia
 Share

Recommended Posts

Hello everyone,I have created a database and i want to add a foreign key to one of my tables.I am using the following command but doesn't work

Alter TABLE SC_Orders ADD FOREIGN KEY (StocklistID) REFERENCES SC_stocklist(StocklistID);

Does anyone know what might be the error and suggest anything?Thank you in advance,Xenia :)

Link to comment
Share on other sites

Thank you aspnetguy,But again nothing happen, the problem is that when i run the command it doesn'tdisplay any error just in the table i cannot see it.Any other suggestions please?

before you run the ALTER TABLE query is StocklistID already a column in the table? Or are you expecting it to be added when you run the query.
Link to comment
Share on other sites

I have already created the column but again it doesn't work

Ok then if you are setting an existing column as a foreign key then there will be no visible changes tot he table. It is just creating a relationship between the 2 tables.It will have effects when Updating/inserting and delteing from the 2 tables but nothing you can see.
Link to comment
Share on other sites

Ok then if you are setting an existing column as a foreign key then there will be no visible changes tot he table. It is just creating a relationship between the 2 tables.It will have effects when Updating/inserting and delteing from the 2 tables but nothing you can see.

I tried to add data to the table but the value for the foreign key didn't display it.Normally when i was adding data tis column would have taken the value from the parent table.Is that right?So because it doesn't do that i supposed that the foreign key was not created
Link to comment
Share on other sites

I tried to add data to the table but the value for the foreign key didn't display it.Normally when i was adding data tis column would have taken the value from the parent table.Is that right?So because it doesn't do that i supposed that the foreign key was not created

Do you think that i can connect two tables without including their foreign keys?MySQL supports the Alter command which add a foreign key?I would be very gretful if you could you please answer my questions?Thank you very much,Xenia
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...