Google

Sunday, October 7, 2007

How to assign ownership to a newly-attached SQL Database

After attaching a new database, eg, the pubs database (through the pubs.mdf file), there is no owner. To assign a new owner, perform the following steps.


1. Create a new login:

Use MS SQL Server Management Studio and create a new login. Click on the Sercurity Node. Right-click on Login. In the Context Menu, click New Login... Add the new user.





2. Assign the new user to the pubs database:

Expand the Databases Node. Right-click pubs database, then select Properties. In the database properties dialog, select Files. Besides the Owner Textbox, click on the ellipses... then select the newly created user from the ListBox.





3. Alternative Solution

Alternatively, instead of adding a new user, you can use the existing sa user. This user is automatically created when installing MS SQL Server 2005. Assign ownership to sa also solves the problem.