SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Column is not the same data type as referencing
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Chubbs
Starting Member

1 Posts

Posted - 07/18/2012 :  19:40:07  Show Profile  Reply with Quote
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 1
Column '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 1
Could 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

India
47173 Posts

Posted - 07/18/2012 :  20:15:19  Show Profile  Reply with Quote
yep...you've to change them to be of same datatype to maintain fk constraint as then error message suggests

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

prett
Posting Yak Master

USA
161 Posts

Posted - 07/19/2012 :  05:57:49  Show Profile  Reply with Quote
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/-
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000