我通过搜索 UniqueColID 并将结果插入回表中来复制记录..这样做我有一个重复的条目,这是我想要的,除了我希望一个列不重复并且该列是 UniqueColID..
下面是我的代码:
CREATE PROCEDURE [dbo].[InsertDuplicateFields]
(@UniqueColID varchar(50), @IndividualID varchar(50) = null)
AS
Begin
INSERT INTO TableCollisionBegin
SELECT * FROM TableCollisionBegin
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableCollisionDetails
SELECT * FROM TableCollisionDetails
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableCollisionLocation
SELECT * FROM TableCollisionLocation
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableDriver
SELECT * FROM TableDriver
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableFollowUp
SELECT * FROM TableFollowUp
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableOfficerLogs
SELECT * FROM TableOfficerLogs
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TablePolice
SELECT * FROM TablePolice
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableRecVerified
SELECT * FROM TableRecVerified
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableSignature
SELECT * FROM TableSignature
WHERE [IndividualID] = @IndividualID;
INSERT INTO TableTrailer
SELECT * FROM TableTrailer
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableValidateLog
SELECT * FROM TableValidateLog
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableVehicle
SELECT * FROM TableVehicle
WHERE [UniqueColID] = @UniqueColID;
INSERT INTO TableWitness
SELECT * FROM TableWitness
WHERE [UniqueColID] = @UniqueColID;
End
每个表都有 NUMEROUS 列,但它们都共享 UniqueColID。
当我插入重复项时,我希望所有详细信息都是重复的,但我想插入一个新的 UniqueColID ..我该怎么做?
新的 UniqueColID 由 ASP.NET 代码中的特殊方法生成。我想要 2 或 3 或 4 个不同的 UniqueColID,其余列重复。
我尝试了你说的第二个代码块,但得到了错误:
"Unknown object type 'TEMPORARY' used in a CREATE, DROP, or ALTER statement."
CREATE PROCEDURE [dbo].[AmendInsertDuplicateFields] (@UniqueColID varchar(50), @NewUniqueColID varchar(50))
AS
Begin CREATE TEMPORARY TABLE Temp AS SELECT * FROM [MVCNew].[dbo].[CollisionBegin] WHERE [UniqueColID] = @UniqueColID;
UPDATE Temp SET UniqueColID = @NewUniqueColID;
INSERT INTO [MVCNew].[dbo].[CollisionBegin] SELECT * FROM Temp;
DROP TEMPORARY TABLE IF EXISTS Temp;
End
我只是在想....我是否可以插入一条带有一些随机 UniqueColID 值的新记录,但所有其他列都插入了值“o”或“u”或“一些随机文本”,然后我插入到这个新记录 UniqueColID 的所有列,除了 UniqueColID?这样,我将拥有一个新的 UniqueColID,其余列具有相同的值。
KCD 我已经尝试了你的代码块并且没有工作.. :(
我个人看不到 SELECT @NewUniqueColID.... 甚至是如何工作的,因为表中没有名为 @NewUniqueColID 的值的列