Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    1

    Question Unanswered: same uniqueidentifier

    Hi,
    how to insert diffrent records into diffrent sql tables with same uniqueidentifier?plz give syntax for this.

    tanx

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    The whole idea of a GUID it that you will never get the same value for it twice, so you will have to store its value in a variable to be able to reuse it in other tables/records.
    Code:
    DECLARE @GUID UNIQUEIDENTIFIER
    SELECT @GUID = NewID()
    INSERT INTO parentTable (Id, column1, column2, column3)
    VALUES(@GUID, 12, 'Hi', 'World')
    INSERT INTO childTable (id, ParentId, columnA, columnB, columnC)
    VALUES(1, @GUID, 'How', 'are', 'You?')
    INSERT INTO childTable (id, ParentId, columnA, columnB, columnC)
    VALUES(2, @GUID, 'I', 'am ', 'fine.')
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Code:
    INSERT INTO table1 (myguid) VALUES ('F745439C-0515-4CFB-B90C-FD9552669225')
    
    INSERT INTO table2 (myguid) VALUES ('F745439C-0515-4CFB-B90C-FD9552669225')
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •