Last active
January 13, 2021 14:35
-
-
Save weeksdev/fb7dc26831ccb45c0ef7dd09654c34ae to your computer and use it in GitHub Desktop.
Create Database MS Sql Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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