Today we will learn on how to create a script that creates logins and give appropriate permissions within Azure SQL
Run the below script in your Azure SQL server:
--create a login. supply the login account name
-- login can also be a user's azure login email that you want to add to SQL to give permissions
use [master]-- login can also be a user's azure login email that you want to add to SQL to give permissions
create login [<login account>] from external provider
go
----add the login to the database.
use [<Database name>]
go
create user [<login account>] from login [<login account>] with default_schema = [DBO];
go
---Create a db_executor role within the database
use [<Database name>]
go
create role [db_executor]
go
Grant execute on schema ::dbo to db_Executor
go
---give db executor permission to the user for the database
exec sp_addrolemember N'db_executor',N'<login account>'
go
---give data reader permission to the user for the database
exec sp_addrolemember N'db_datareader',N'<login account>'
go
---give data writter permission to the user for the database
exec sp_addrolemember N'db_datawriter',N'<login account>'
go
---give ddl admin permission to the user for the database
exec sp_addrolemember N'db_ddladmin',N'<login account>'
go
