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. Creating New Database in SQL 2012 Management Studio

Creating New Database in SQL 2012 Management Studio

Scheduled Pinned Locked Moved Database
databasequestion
6 Posts 4 Posters 2 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.
  • G Offline
    G Offline
    Gary Heath
    wrote on last edited by
    #1

    Fairly basic question really, if each of my Tables has a Primary Key of UNIQUEIDENTIFIER, when I create a Foreign Key to point at the PK of another Table, what Data Type should it be ?

    L A 2 Replies Last reply
    0
    • G Gary Heath

      Fairly basic question really, if each of my Tables has a Primary Key of UNIQUEIDENTIFIER, when I create a Foreign Key to point at the PK of another Table, what Data Type should it be ?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Also uniqueidentifier. Types of PK and FK needs to match.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      G 1 Reply Last reply
      0
      • L Lost User

        Also uniqueidentifier. Types of PK and FK needs to match.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        G Offline
        G Offline
        Gary Heath
        wrote on last edited by
        #3

        Really ? I (obviously wrongly !) assumed that a UniqueIdentifier value would be generated anew when a record was created, rather than used from another field ... I have a lot to learn here :-O !!!

        B L 2 Replies Last reply
        0
        • G Gary Heath

          Really ? I (obviously wrongly !) assumed that a UniqueIdentifier value would be generated anew when a record was created, rather than used from another field ... I have a lot to learn here :-O !!!

          B Offline
          B Offline
          Bram van Kampen
          wrote on last edited by
          #4

          Hi, As I understand it, A Unique Identifier is only created if you also set it as Primary Key. Regards :)

          Bram van Kampen

          1 Reply Last reply
          0
          • G Gary Heath

            Really ? I (obviously wrongly !) assumed that a UniqueIdentifier value would be generated anew when a record was created, rather than used from another field ... I have a lot to learn here :-O !!!

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Gary Heath wrote:

            I (obviously wrongly !) assumed that a UniqueIdentifier value would be generated anew when a record was created, rather than used from another field

            They're not generated by default; it's just a datatype to hold GUID's. For the Primary Key to generate one, it'll have to have a default - usually coming from the NewId function. The PK is the unique value that identifies your record. An FK only references it; we copy the unique value of the PK that we want to link, and keep that information in the FK.

            Person
            PersonId -- (PK, gets the value from it's default)
            Name
            OtherStuff

            User
            UserId -- (PK of this table)
            PersonId -- (FK of Person, to link that person-record to this one)

            Person1: 145, Joe, Stuff User1: 132, 145 -- referencing a user by using it's PK

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            1 Reply Last reply
            0
            • G Gary Heath

              Fairly basic question really, if each of my Tables has a Primary Key of UNIQUEIDENTIFIER, when I create a Foreign Key to point at the PK of another Table, what Data Type should it be ?

              A Offline
              A Offline
              Amol_B
              wrote on last edited by
              #6

              I think it should be on same data type

              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