relationship creation issue
-
hello i was creating relationship betwween 2 tables with different data types for the primarykeys of the two tables. One primary key had data type
int
and the other primary key had data typevarchar
. when i tried to create relationship between the two table, Sql Server gave the error that both the primary key data types are different and hence it didn't create the relationship. so what i want to know is that does the data types of the primary keys have to be the same to create relationship between the tables??? -
hello i was creating relationship betwween 2 tables with different data types for the primarykeys of the two tables. One primary key had data type
int
and the other primary key had data typevarchar
. when i tried to create relationship between the two table, Sql Server gave the error that both the primary key data types are different and hence it didn't create the relationship. so what i want to know is that does the data types of the primary keys have to be the same to create relationship between the tables???Saira Tanwir wrote:
what i want to know is that does the data types of the primary keys have to be the same to create relationship between the tables???
If you want to create a relationship between two tables the type of the primary key on one table must match the foreign key on the other. The only time that two primary keys must match is when you are creating a one-to-one (or zero-to-one) join because the primary keys are also the foreign keys.
Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos
-
hello i was creating relationship betwween 2 tables with different data types for the primarykeys of the two tables. One primary key had data type
int
and the other primary key had data typevarchar
. when i tried to create relationship between the two table, Sql Server gave the error that both the primary key data types are different and hence it didn't create the relationship. so what i want to know is that does the data types of the primary keys have to be the same to create relationship between the tables???Yes.It should be same datatypes while creating a relationship between two tables.
Priya
-
Yes.It should be same datatypes while creating a relationship between two tables.
Priya
Priya_2007 wrote:
It should be same datatypes while creating a relationship between two tables
The OP was asking about two PRIMARY KEYS. The primary keys do NOT have to be the same, and often they are not the same in two related tables. The important part is the PRIMARY KEY on the parent table matches the type of the FOREIGN KEY on the child table. You only need to match both primary keys when you are creating a one-to-one or zero-to-one relationship.
Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos