如何在随机名称上创建角色

时间:2017-12-03 20:58:00

标签: mysql sql sql-server transactions

我想在主持人上创建角色。主持人是前3位用户。主持人角色是更新,删除,插入。怎么决定呢?

create table TmpUsers(
    ID  int identity (1,1) primary key not null,
    UserID nvarchar(10) not null,
    Pass nvarchar(20) not null,
    LastLogin datetime not null,
    LastLogOut datetime not null
)
DECLARE @sql NVARCHAR(4000),
        @username nvarchar(6),
        @password nvarchar(6),
        @random int,
        @count int
set @count=1;
While(@count<10) 
begin 
SET NOCOUNT ON
   set @username = 'User'+CONVERT(nvarchar,@count)
   set @random = (select RAND()*98+1)
   set @password = 'User'+CONVERT(nvarchar,@count)
    SET @SQL = 'CREATE LOGIN ' + @username + ' WITH PASSWORD = '+''+@password+''+', DEFAULT_DATABASE=[Patient]';
   EXECUTE(@SQL)
             set @count=@count+1;
             Insert into TmpUsers([UserID],[Pass])
             values(@username,@password)
             create role UserID
             grant select on OnlineGutal to NS
             where (select ID from TmpUsers = 1) 
             EXEC sp_addrolemember 'UserID', 'NS';
end

0 个答案:

没有答案