How to generate and manually insert a uniqueidentifier in sql server?

后端 未结 2 1254
南旧
南旧 2021-02-05 02:51

I\'m trying to manually create a new user in my table but impossible to generate a \"UniqueIdentifier\" type without threw an exception ...

Here is my example:



        
相关标签:
2条回答
  • 2021-02-05 03:11

    ApplicationId must be of type UniqueIdentifier. Your code works fine if you do:

    DECLARE @TTEST TABLE
    (
      TEST UNIQUEIDENTIFIER
    )
    
    DECLARE @UNIQUEX UNIQUEIDENTIFIER
    SET @UNIQUEX = NEWID();
    
    INSERT INTO @TTEST
    (TEST)
    VALUES
    (@UNIQUEX);
    
    SELECT * FROM @TTEST
    

    Therefore I would say it is safe to assume that ApplicationId is not the correct data type.

    0 讨论(0)
  • 2021-02-05 03:20

    Kindly check Column ApplicationId datatype in Table aspnet_Users , ApplicationId column datatype should be uniqueidentifier .

    *Your parameter order is passed wrongly , Parameter @id should be passed as first argument, but in your script it is placed in second argument..*

    So error is raised..

    Please refere sample script:

    DECLARE @id uniqueidentifier
    SET @id = NEWID()
    Create Table #temp1(AppId uniqueidentifier)
    
    insert into #temp1 values(@id)
    
    Select * from #temp1
    
    Drop Table #temp1
    
    0 讨论(0)
提交回复
热议问题