Thursday, November 16, 2017

SQL Server, Add New Login as sysadmin without Management Studio (SSMS)

How to Control MS SQL Server  without Management Studio (SSMS) :
For E.g:
We need to create new user account and we do not have SSMS installed on the server, for a quick Solution we did the following :

1- Prepare our SQL script in txt file :
--------------- Script.txt --------------------
USE [master]
GO
CREATE LOGIN [nady] WITH PASSWORD=N'123', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
EXEC master..sp_addsrvrolemember @loginame = N'nady', @rolename = N'sysadmin'
GO
------------------------------------------------

2- Prepare Command :
--------------- CMD.txt --------------------
sqlcmd -S dpqdevecom01 -i C:\nady\Script.txt -o C:\nady\Exec_Output.txt
------------------------------------------------

3- Open Windows command line, CMD ( Windows + R) then Paste your Command Script :) .




No comments: