Xenia Posted February 15, 2006 Share Posted February 15, 2006 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 More sharing options...
aspnetguy Posted February 15, 2006 Share Posted February 15, 2006 take a look at thishttp://www.1keydata.com/sql/sql-foreign-key.html Link to comment Share on other sites More sharing options...
Xenia Posted February 15, 2006 Author Share Posted February 15, 2006 take a look at thishttp://www.1keydata.com/sql/sql-foreign-key.html<{POST_SNAPBACK}> 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? Link to comment Share on other sites More sharing options...
aspnetguy Posted February 15, 2006 Share Posted February 15, 2006 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?<{POST_SNAPBACK}> 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 More sharing options...
Xenia Posted February 15, 2006 Author Share Posted February 15, 2006 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.<{POST_SNAPBACK}> I have already created the column but again it doesn't work Link to comment Share on other sites More sharing options...
aspnetguy Posted February 15, 2006 Share Posted February 15, 2006 I have already created the column but again it doesn't work<{POST_SNAPBACK}> 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 More sharing options...
Xenia Posted February 15, 2006 Author Share Posted February 15, 2006 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.<{POST_SNAPBACK}> 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 More sharing options...
Xenia Posted February 16, 2006 Author Share Posted February 16, 2006 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<{POST_SNAPBACK}> 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now