Creating New Database in SQL 2012 Management Studio
-
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 ?
-
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 ?
-
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 !!!
-
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 !!!
Hi, As I understand it, A Unique Identifier is only created if you also set it as Primary Key. Regards :)
Bram van Kampen
-
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 !!!
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
OtherStuffUser
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[^]
-
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 ?