create-sqlserver-login-and-database.sql 859 B

12345678910111213141516171819202122232425262728
  1. -- This SQL Server T-SQL script creates the database user and hello_world database.
  2. --
  3. -- To run this script, login to an administrator account in Windows, open a command prompt and run:
  4. --
  5. -- "%ProgramFiles%\Microsoft SQL Server\110\Tools\binn\sqlcmd.exe" -i <filename of this file>
  6. --
  7. IF EXISTS (SELECT * FROM sys.server_principals WHERE name = 'benchmarkdbuser')
  8. DROP LOGIN benchmarkdbuser
  9. GO
  10. -- This password has mixed-case and a number to satisfy the Windows password policy
  11. CREATE LOGIN benchmarkdbuser WITH PASSWORD = 'B3nchmarkDBPass'
  12. GO
  13. IF EXISTS(SELECT * FROM SYS.DATABASES WHERE NAME='hello_world')
  14. DROP DATABASE hello_world
  15. GO
  16. CREATE DATABASE hello_world
  17. GO
  18. USE hello_world
  19. GO
  20. -- Give this user total power over the database
  21. CREATE USER benchmarkdbuser FOR LOGIN benchmarkdbuser
  22. EXEC sp_addrolemember 'db_owner', 'benchmarkdbuser'
  23. GO