Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. relationship creation issue

relationship creation issue

Scheduled Pinned Locked Moved Database
helpdatabasesql-serversysadminquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saira Tanwir
    wrote on last edited by
    #1

    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???

    C P 2 Replies Last reply
    0
    • S Saira Tanwir

      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???

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • S Saira Tanwir

        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???

        P Offline
        P Offline
        Priya_2007
        wrote on last edited by
        #3

        Yes.It should be same datatypes while creating a relationship between two tables.

        Priya

        C 1 Reply Last reply
        0
        • P Priya_2007

          Yes.It should be same datatypes while creating a relationship between two tables.

          Priya

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups