loop for multiple database and user creation in sql, need to assign the user to the database. anyone please help me with that code :       

>  ***after creating login using windows authentication ,
         need to assign user to the database 
         and provide permissions to that user.
         Could anyone please help me with that. 
        Thanks in advance.*** 

                    
        -- BULK INSERT tempNames.dbo.tempNames
                 --      FROM 'C:\Users\Videos\file.txt'
                    --   WITH 
                --        (
                      --      ROWTERMINATOR ='\n'--
                        --  )
                    	  
                    USE [master]
                    GO
                    
                    DECLARE @NameCursor as CURSOR;
                    DECLARE @NAME AS NVARCHAR(50);
                    DECLARE @NAME2 AS NVARCHAR(50);
                    DECLARE @NIUNT AS NVARCHAR(50);
                    
                    SET @NIUNT ='niunt';
                    
                    SET @NameCursor = CURSOR FOR
                    SELECT id
                     FROM test.dbo.Sheet1$
                     
                    OPEN @NameCursor;
                    FETCH NEXT FROM @NameCursor INTO @Name;
                    
                    WHILE @@FETCH_STATUS = 0
                    BEGIN
                    PRINT @Name 

## Creating database  using @name ##

                    set @name2 ='create database '+@Name + ';'
                    
                      exec (@name2)
                    
                      BEGIN
                    	SET NOCOUNT ON
                    	DECLARE @SQL NVARCHAR(4000);
                    
## Creating login using @name ##
                    	
                    	SET @SQL = 'CREATE LOGIN [' +@NIUNT +'\'+ @NAME + '] from windows';                    
                    	exec(@SQL); 
                    	  
                    	-END;
                    
                   
                     FETCH NEXT FROM @NameCursor INTO @Name;
                    
                     END 
                    
                    GO

       

