18 lines
513 B
Transact-SQL
18 lines
513 B
Transact-SQL
use EnVisage
|
|
|
|
alter table Resource add TeamId uniqueidentifier null
|
|
go
|
|
|
|
ALTER TABLE [dbo].[Resource] WITH CHECK ADD CONSTRAINT [FK_Resource_Team] FOREIGN KEY([TeamId])
|
|
REFERENCES [dbo].[Team] ([Id])
|
|
GO
|
|
|
|
ALTER TABLE [dbo].[Resource] CHECK CONSTRAINT [FK_Resource_Team]
|
|
GO
|
|
|
|
update Resource
|
|
set TeamId = (select top 1 a.TeamId
|
|
from (select *, ROW_NUMBER() OVER (PARTITION BY TeamId ORDER BY ResourceId) AS RowNumber from Resource2Teams) as a
|
|
where a.ResourceId = Id and a.RowNumber = 1)
|
|
|
|
drop table Resource2Teams |