|
-- alter table University add GID uniqueidentifier not null DEFAULT (newsequentialid()) --ALTER TABLE Student ALTER COLUMN UniversityID nvarchar(250) -- [null | not null] --alter table Student drop CONSTRAINT FK_Student_University begin tran begin try DECLARE @ID NVARCHAR(250)=''; DECLARE @G_ID NVARCHAR(250)=''; DECLARE Table_Cursor CURSOR FOR SELECT ID,GID from University OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @ID,@G_ID WHILE (@@FETCH_STATUS = 0) BEGIN update Student set UniversityID=@G_ID where UniversityID=@ID FETCH NEXT FROM Table_Cursor INTO @ID,@G_ID END CLOSE Table_Cursor DEALLOCATE Table_Cursor COMMIT END TRY BEGIN CATCH ROLLBACK END CATCH
|