Skip to content

Instantly share code, notes, and snippets.

@weeksdev
Last active January 13, 2021 14:35
Show Gist options
  • Save weeksdev/fb7dc26831ccb45c0ef7dd09654c34ae to your computer and use it in GitHub Desktop.
Save weeksdev/fb7dc26831ccb45c0ef7dd09654c34ae to your computer and use it in GitHub Desktop.
Create Database MS Sql Server
CREATE LOGIN {{username}} WITH PASSWORD = '{{strong_password}}';
CREATE DATABASE {{database_name}};
ALTER DATABASE {{database_name}} SET RECOVERY SIMPLE;
ALTER AUTHORIZATION ON DATABASE::{{database_name}} TO {{username}};
SELECT suser_sname (owner_sid), * FROM sys.databases ORDER BY name WHERE name = '{{database_name}}';
--FOR WINDOWS LOGIN
create login [<<DOMAIN\USERNAME>>] from windows;
-- For older versions of SQL Server:
EXEC sys.sp_addsrvrolemember @loginame = N'<<DOMAIN\USERNAME>>', @rolename = N'sysadmin';
-- For newer versions of SQL Server:
ALTER SERVER ROLE [sysadmin] ADD MEMBER [<<DOMAIN\USERNAME>>];
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment