I have an old database which I am trying to convert to new database structure but before continue I want to know if is there any best method to do do. I have tried using Cursor but it takes time. I have total 13 tables to migrate from old database to new database.
DECLARE @GGroupId as Int;
DECLARE @GName as NVARCHAR(MAX);
DECLARE @GDescription as NVARCHAR(MAX);
DECLARE @GLastModification as DateTime;
DECLARE @GLastUser as NVARCHAR(MAX);
DECLARE @Prio as int;
DECLARE @NEW_GROUP_ID as int;
DECLARE @PProupId as Int;
DECLARE @PName as NVARCHAR(MAX);
DECLARE @PDescription as NVARCHAR(MAX);
DECLARE @PLastModification as DateTime;
DECLARE @PLastUser as NVARCHAR(MAX);
DECLARE Group_Cursor CURSOR FOR
SELECT Ord_Id, Bezeich,Notiz, Prio
FROM [MigrationAPlanDB].[dbo].[Ordner];
OPEN Group_Cursor
FETCH NEXT FROM Group_Cursor INTO @GGroupId, @GName, @GDescription, @Prio;
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @USERID as int;
/*SELECT U.Id from [MigrationAPlanDB].[dbo].User_Names as U where U.User = @GLastUser INTO @USERID;*/
INSERT INTO [ProjectManagement].[dbo].[Groups] (Name, Description, Priority ,CreatorId, InsertDate, IsDeleted)
VALUES (@GName, cast(@GDescription as ntext), @Prio, 1, GETDATE(), 0)
SET @NEW_GROUP_ID = SCOPE_IDENTITY()
DECLARE Project_Cursor CURSOR FOR
SELECT Pro_ID,Bezeich, Notiz, LastModification, LastUser FROM [MigrationAPlanDB].[dbo].[Projekte] WHERE Ord_Id = @GGroupId;
OPEN Project_Cursor;
FETCH NEXT FROM Project_Cursor INTO @PProupId, @PName, @PDescription, @PLastModification, @PLastUser;
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO [ProjectManagement].[dbo].[Projects] (Name, Description,UpdateDate
,CreatorId, InsertDate) VALUES (@PName, @PDescription, @PLastModification, 1, GETDATE());
/*SELECT SCOPE_IDENTITY() INTO @NEW_PROJECT_ID;*/
END;
CLOSE Project_Cursor
DEALLOCATE Project_Cursor
END;
CLOSE Group_Cursor
DEALLOCATE Group_Cursor
GO
Aucun commentaire:
Enregistrer un commentaire