Home Forums SQL Server 2008 T-SQL (SS2K8) Need to insert Reocrds in uniqueidentifier column RE: Need to insert Reocrds in uniqueidentifier column

  • ChrisM@home (4/20/2011)


    It doesn't work because '00000000-0000-0000-000-0000000000' won't cast to a uniqueidentifier. Try this:

    SELECT CAST('00000000-0000-0000-000-0000000000' AS uniqueidentifier)

    SELECT CAST('00000000-0000-0000-0000-000000000000' AS uniqueidentifier)

    Why do you want to put this value into a uniqueidentifier column? Why not use NEWID()?

    Using CAST() like this solved a similar issue I was working with. As to "Why not use NEWID()", because the existing application uses the same guid to link several different tables. Definitely poor design! And there were duplicate records in one of the those tables, another poor design decision. I had to delete the duplicated records, and re-insert (using the CAST()) just one record with the correct data. Note that the table does not have an identity column. Sigh!