Adding an administrator user to SQL Server 2008

How do you add an administrator user to SQL Server 2008?


If you're doing it via T-SQL:

Granting a Windows Login the ability to connect to SQL Server:

CREATE LOGIN [Domain\User] FROM WINDOWS;

or

CREATE LOGIN [Domain\Group] FROM WINDOWS;

If SQL Server-based login:

CREATE LOGIN [LoginName] WITH PASSWORD = 'SomePassword';

After that, you can do one of two things. You can add it to the membership of the sysadmin fixed server role using sp_addsrvrolemember:

EXEC sp_addsrvrolemember 'LoginName', 'sysadmin';

or you can grant the login CONTROL SERVER permissions:

GRANT CONTROL SERVER TO [LoginName];

Before that I think we need to be able to login to SQL Server first. I have experienced being a server administrator, but I couldn't login since SQL Server was installed by a Domain Admin account.

So you might need to start SQL Server with command-line option -m (single user mode),

sqlservr.exe -m 

and then do as K. Brian Kelley said, or connect via management studio, as suggested by Jeff (the login will succeed)

More step-by-step instructions can be found in SQL Server 2008: Forgot to add an administrator account?