I have a table for Users and another for Role and a table between them Access
How can I add a role to all of users in a SQL query?
Table User:
ID Name ...
1
5
9
10
11
Table Role :
Id ....
10
11
12
Table Access:
UserID RoleID
1 10
2 10
3 10
4 10
I want to do it with Loop, means from row 1 of User to end
Update :
I am using:
DECLARE @roleId int
SET @roleId = 79
INSERT INTO Access (Users.code, @roleId)
SELECT code, @roleId
FROM Users
I get an error:
Incorrect syntax near '@roleId'.