I have a stored procedure which creates dynamic SQL from user input and executes it.
create proc MySP @input nvarchar(max)
as
declare @sql nvarchar(max) = // generate sql using @input and data from tables
-- The generated SQL will need to access linked server too
exec(@sql)
To prevent SQL injection attack of insert, delete, update, drop, etc. (select is ok), will exec(@sql) as login='aReadonlyLogin' work? Is it a way without using a read-only login? The developer may not have permission to create a new login.