Solved

Is it possible to create a Foreign Key from BIGINT to NUMERIC(19,0) in SQL Server 2005?

Posted on 2008-06-19
4
363 Views
Last Modified: 2012-06-27
I have two tables.

TEST1
TEST_KEY numeric(19,0) IDENTITY,
TEST_DESC varchar(20)

TEST2
TEST_KEY BIGINT NOT NULL
TEST_NAME varchar(50)

I am trying to use SQL Analysis Server to create a relationship between those two tables but I get an error that the data types are different. Is there a setting to let SQL Server know that they are similar and to allow the relationship to be built?
0
Comment
Question by:gumby34
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
vasureddym earned 125 total points
Comment Utility
There are 2 rules to create a foreign key:
1) There should be a primary key on the master table. In your example, it is not clear about the primary key.
2) The datatypes of the Primary key in the master table and the referring column in the child table must be same. in your example, the two columns are of different datatype  numeric(19,0) and Bigint.

If these two rules are not met SQL Server doesn't allow to create FK.
0
 
LVL 60

Expert Comment

by:chapmandew
Comment Utility
I am pretty sure that AA requires that the two fields be of the exact same data type...
0
 

Author Comment

by:gumby34
Comment Utility
vasureddym: Thanks I forgot to include the PK info. Both tables have the PK defined as the TEST_KEY.

chapmandew: Thanks for the reply

I guess that we will have to change the datatypes on the second table to numeric(19,0) in order to get this to work.
0
 

Author Closing Comment

by:gumby34
Comment Utility
Thanks for your help
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now