【发布时间】:2020-08-26 04:55:50
【问题描述】:
我插入一个表然后取回 ID 以便我可以插入另一个表的正常过程在 MSSQL 中是这样的:
DECLARE @transactionKey uniqueidentifier
SET @transactionKey = NEWID()
INSERT INTO transactions(transactionKey, transactionDate, transactionAmount)
VALUES(@transactionKey, '#transactionDate#', '#transactionAmount#')
DECLARE @transactionID int
SELECT @transactionID = transactionID
FROM transactions
WHERE transactionKey = @transactionKey
INSERT INTO transactionItems(transactionID, itemID, itemAmount)
VALUES(@transactionID, '#itemID#', '#itemAmount#')
SELECT @transactionID as transactionID
我的问题分为两部分。首先,这是最好的方法吗?我读到 GUID 有可能在我身上发生变化,最终我在第二个表中得到了无效的 GUID。我假设这种情况的可能性非常小,而且我多年来一直在各种项目中这样做并且从未遇到过问题。
我的问题的第二部分是这样的事情在 MySQL 中是否有效?我开始使用 MySQL 开展一个新项目,但我不确定最好的方法。我过去通常只在 MSSQL 上工作过。
我在这个新项目中使用 CF9 和 MySQL。
在这方面的任何帮助都会很棒。
提前致谢。
【问题讨论】:
-
回复:我读到我的 GUID 有可能发生变化你从哪里读到的?
标签: mysql sql-server coldfusion