Здравствуйте, gandjustas, Вы писали:
G>>>G>>>create view UserNodeJunction with schemabinding as
G>>>select
G>>> un1.NodeId as Node1Id,
G>>> un1.UserId as User1Id,
G>>> un2.NodeId as Node2Id,
G>>> un2.UserId as User2Id
G>>>from UserOnNode un1
G>>>join User_User uu on uu.User1Id = un1.UserId -- Берем связи пользователя
G>>>join UserOnNode un2 on un2.UserId = uu.User2Id
G>>>create clustered index PK_UserNodeJunction on UserNodeJunction (Node1Id, User1Id, Node2Id, User2Id)
G>>>create index IX_NodeLink on UserNodeJunction (Node1Id, Node2Id)
G>>>
я что-то поторопился.
Нужно такой запрос делать:
create view Node_Node with schemabinding as
select
un1.NodeId as Node1Id,
un2.NodeId as Node2Id,
count_big(*) as cnt
from UserOnNode un1
join User_User uu on uu.User1Id = un1.UserId
join UserOnNode un2 on un2.UserId = uu.User2Id
group by un1.NodeId, un2.NodeId
create clustered index PK_UserNodeJunction on Node_Node (Node1Id, Node2Id)
И вообще забыть про вставки и прочую лабуду.