我有一個表,有一個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