10 Nov 2021
This post is just basically a SQL snippet for you to copy, paste and edit for use when you need to create a SQL database with a login and a user.
I use it when creating databases for Umbraco websites.
Just do a find and replace for 'mydatabase' with whatever you want to call your database and change the password of course!
USE master GO CREATE DATABASE [mydatabase] CREATE LOGIN [mydatabase-login] WITH password='supersecretpassword1='; USE [mydatabase] GO CREATE USER [mydatabase-user] FROM LOGIN [mydatabase-login]; EXEC sp_addrolemember 'db_datawriter', 'mydatabase-user' EXEC sp_addrolemember 'db_ddladmin', 'mydatabase-user' EXEC sp_addrolemember 'db_datareader', 'mydatabase-user'