Andras

Software Architect - Red Gate Software

Do you need to be dbo to compare two databases using SQL Compare?

Published Monday, July 30, 2007 10:01 AM

This question comes up time to time. SQL Compare compares two database schemata, and in order to do so it needs to read the system tables and system views. On the other hand, some organizational policies can be rather restrictive about who and with what permissions are allowed to connect to a production system.

 

The more complex databases make use of object owners to organise the database objects. Objects like tables, views, user defined types can be owned by individual users/schemas. Under SQL Server 2000, in order to read all the schema information, you do need to be dbo, otherwise you will not be able to see some of the object definitions, or you will not be able to learn about the existence of certain database objects.

 

Under SQL Server 2005 however there is a permission (VIEW DEFINITION) to control access to viewing object definitions. To add this permission to user UserA in a particular database run:

 

GRANT VIEW DEFINITION TO UserA;

 

You can also grant this permission at server level by executing:

 

GRANT VIEW ANY DEFINITION UserA;

 

The nice thing about this is that with the help of the above permission you are not granting permission to modify the database schema, so you can allow people to use SQL Compare to compare and monitor schema changes without allowing them to modify the databases in question. You can still generate a synchronization script, but that you can later execute as a different user.

 

Andras

by András

Comments

 

JasonKeith said:

This is a great piece of information! I have used this technique to script using Red Gate SQL Compare. I still have one problem. I can't see permissions for groups I am not a part of. For example in SIT I have access to execute stored procedures. I am a member of an AD_Group called exec_SP. In UAT I do not have this permisssion (I am not in the exec_SP group). When I run Red Gate I see changes for the exec_SP group on all stored procedures. This is because I don't see the group in UAT because I am not part of it.
August 21, 2007 3:40 PM
You need to sign in to comment on this blog

About András

András Belokosztolszki is the architect of SQL Compare versions 4, 5, 6 and 7, SQL Log Rescue and SQL Refactor. He is focused on database internals, database synchronization and database schema evolution.

















<July 2007>
SuMoTuWeThFrSa
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234
Go With the Flow
 Knowing enough about the routes that messages take is vital to being an effective Exchange admin,... Read more...

When Email Collaboration Could Have Changed History
 In our mission to make history relevant to the busy IT executive, we speculate how Email might have... Read more...

Bunnikins!
 When an IT manager is selected as a victim of office politics of a large corporate, it is time for him... Read more...

Exchange Database Technologies
 One of the most misunderstood technologies in Exchange Server, regardless of its version, is the... Read more...

Top Tips for Exchange Admins
 Michael Francis hands out imaginary Olympic medals to the winner of the August 'Top Tips for Exchange... Read more...