Monday, June 29, 2026

Create db and user on SQLServer

CREATE DATABASE MyNewDatabase; GO -- Step 1: Create a Login at the Server level CREATE LOGIN MyNewLogin WITH PASSWORD = 'YourStrongPassword123!'; GO -- Step 2: Switch to your specific database USE MyNewDatabase; GO -- Step 3: Create a Database User mapped to that Login CREATE USER MyNewUser FOR LOGIN MyNewLogin; GO -- Step 4: Grant Permissions (Assign a role) -- Option A: Give them full read/write access ALTER ROLE db_datareader ADD MEMBER MyNewUser; ALTER ROLE db_datawriter ADD MEMBER MyNewUser; GO -- Option B: Give them full admin access to this specific database instead -- ALTER ROLE db_owner ADD MEMBER MyNewUser; -- GO