我有一个表,有一个newid()为主键字段(Id)返回一个自动创建的GUID ID的最佳方式是什么?
在存储过程我需要返回这个新创建的GUID返回作为返回参数,我可以事先创建GUID并插入到数据库中,但是这会破坏newid()的目的。有处理这个问题的好方法吗?
INSERT INTO [SUBS].[dbo].[Subscriptions]
([CustomerId]
,[SubscriptionClassId]
,[StartDate]
,[TrialAmount]
,[Amount]
,[TrialInterval]
,[Interval]
,[TrialIntervalLength]
,[IntervalLength]
,[CreatedBy]
,[LastUpdatedBy])
VALUES
(@CustomerId
,@SubscriptionClassId
,@StartDate
,@TrialAmount
,@Amount
,@TrialInterval
,@Interval
,@TrialIntervalLength
,@IntervalLength
,@CreatedBy
,@CreatedBy)
select @SubscriptionId = SCOPE_IDENTITY() -- this does not work because scope_identity is numeric