使用TSQL为用户提供了所有角色?

时间:2015-09-29 19:35:17

标签: sql sql-server tsql

如何将用户ID为123的用户的Roles表中的ID值插入Security_UserRoles表?

INSERT INTO [Security_UserRoles]
           ([UserID]
           ,[RoleID]
           ,[CreatedBy]
           ,[CreatedOn])
     VALUES
           (123
           ,SELECT [id] FROM [Security_Roles]
           ,'rrr.rrr'
           ,GETDATE())
GO

1 个答案:

答案 0 :(得分:1)

INSERT INTO [Security_UserRoles]
           ([UserID]
           ,[RoleID]
           ,[CreatedBy]
           ,[CreatedOn])
SELECT 123, [id], 'rrr.rrr', getdate() FROM [Security_Roles]