September 22, 2014 at 1:15 pm
Please, if you're familiar with the following script below, can you tell me the logic behind using "SA" login as the database owner for all databases? Is it possible to create a different login account to use for all databases? If so, what privileges should be granted to this login?
USE master
GO
SET NOCOUNT ON
/*Generate an execution script for each database that needs the owner changed*/
DECLARE @LoopExecuteScripts TABLE (exec_command VARCHAR(1000))
INSERT INTO @LoopExecuteScripts
SELECT 'ALTER AUTHORIZATION ON DATABASE::' + name + ' TO sa'
FROM sys.databases
WHERE owner_sid <> 0x01
AND state_desc = 'ONLINE'
/*Loop through each record in @LoopExecuteScripts table and execute the command*/
DECLARE @Current_Record VARCHAR(1000)
SELECT @Current_Record = MIN(exec_command) FROM @LoopExecuteScripts
WHILE @Current_Record IS NOT NULL
BEGIN
PRINT @Current_Record
EXEC (@Current_Record)
--Delete processed record
DELETE FROM @LoopExecuteScripts WHERE exec_command = @Current_Record
--Get next record to be processed
SELECT @Current_Record = MIN(exec_command) FROM @LoopExecuteScripts
END
September 22, 2014 at 1:50 pm
Just to be clear we are talking about the owner of the database and not a discussion about the dbo role. I use 'sa' as the owner of jobs and databases for the most part. You could create a sql account or Windows account (not a user account) to be the owner, but sa is installed with SQL and I know it will be there. There are some gotchas with this and you should check out the following posts:
http://www.sqlservercentral.com/Forums/Topic758243-146-1.aspx Look at EdVassie's posts
http://www.sqlservercentral.com/Forums/Topic687144-146-1.aspx Look at RBarry Youn's post (last one)
These are old posts, but have good information about database owners.
September 22, 2014 at 1:53 pm
This could a good start :
the "Connecting Through SQL Server Authentication" section.
Cheers,
Iulian
September 23, 2014 at 8:18 am
The question is about the owner of the database and not the db_owner role.
Thanks for the response.
September 25, 2014 at 3:42 pm
I will suggest that to counter these kind of questions please visits websites like http://www.techgurulab.com. Where you can get all kind of stuff i.e; Quizzes, Tutorial, Tests and Study Materials. These will help to build basic concepts of your own.
September 25, 2014 at 3:43 pm
I will suggest that to counter these kind of questions please visits websites like www[dot]techgurulab[dot]com. Where you can get all kind of stuff i.e; Quizzes, Tutorial, Tests and Study Materials. These will help to build basic concepts of your own.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply