Creating new login in SQL Server througth T-SQL script

In my last post I show You how create login in server, in this I present how do it througth T-SQL query.

First go to Security->Logins node and expands it.

vv1

You see defaut sa login and login creating in last post throught SQL Server Management Studio. Go to the query editor and copy this code:

CREATE LOGIN dorota
WITH PASSWORD = 'DoRoTa2211';
GO

This sql query create login dorota. After WITH PASSWORD = You must write as text password for this login. My password is DoRoTa2211 . If You execute this query, show Logins node in Object Explorer window. If new login is not visible, refresh this node.

vv2

After refresh You see your new login:

vv3Try to login with it to the Server engine.

vv5

As You may see the databases(except system databases as master, tempdb, … ) will not be accessible for this login and user. Why? Because this creating user is not  admin.

For sa login:

For dorota login:

How change server role?

You may execute procedure adding sysadmin role for server:

exec sp_addsrvrolemember 'dorota', 'sysadmin' ;

In Login Properties window You see new role:

Try connect another time to the server.

Now You see data in all databases.