How to create user for existing I have a database which get restored everyday through a agent job, but after restoration the user gets killed so i want to create a step so that after restoration user should be created with readonly permission.

CREATE USER [username] FOR LOGIN [loginname]
 ALTER ROLE [db_datareader] ADD MEMBER []

Is this ok ?
Is this ok ?

The db_datareader role gives implicit access to SELECT against all tables and views in a database.

If that's ok, then it's ok

You might be interested in the information in this post about db_datareader

You can conditionally check to see if the user already exists

use myDB
GO

if not exists(select * from sys.database_principals where name = 'foo')
-- create your database user


When restoring or attaching databases where the user already exists, you might have to 'remap' any Sql logins to the restored database.  This is what I use as part of normal 'refresh' scripts

use &lt;YourDatabase&gt;
go
set nocount on
declare @cmd varchar(max)=''
select
    @Cmd=@cmd + 'ALTER USER ' + dp.name + ' WITH LOGIN = ' + dp.name + ';' + char(10)
from
    sys.database_principals dp left join
    master.sys.server_principals sp on
        sp.name=dp.name
where
    dp.type='s' and
    dp.default_schema_name&lt;&gt;dp.name and
    sp.name is not null
exec (@cmd)