Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Chubbs
Starting Member
1 Post |
Posted - 2012-07-18 : 19:40:07
|
| Hello everyone,I don't know why sql server management studio is not accepting my foriegn key query. This is what I am trying to add to my database. ALTER TABLE customer_rentals ADD CONSTRAINT fk_customer_rentals_movies FOREIGN KEY(movie_id)REFERENCES movies(movie_id);Msg 1778, Level 16, State 0, Line 1Column 'movies.movie_id' is not the same data type as referencing column 'customer_rentals.movie_id' in foreign key 'fk_customer_rentals_movies'.Msg 1750, Level 16, State 0, Line 1Could not create constraint. See previous errors.When I check the customer_rental column (movie_id) is in the column as a VARCHAR data type. In the movie column (movie_id) is the primary key with an int data type. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-18 : 20:15:19
|
| yep...you've to change them to be of same datatype to maintain fk constraint as then error message suggests------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
prett
Posting Yak Master
212 Posts |
Posted - 2012-07-19 : 05:57:49
|
| Agree with visakh16,This error occurs when you try to create a FOREIGN KEY constraint between columns of different data types. Check this article, it has full description of the error: http://www.sqlerror.sqlserver-training.com/msg-1778-level-16-state-0-line-1-column-ls-ls-is-not-the-same-data-type-as-referencing-column-ls-ls-in-foreign-key-ls/- |
 |
|
|
|
|
|