Set up object locking
Published 16 July 2015
About the setup script
The script adds the trigger RG_SQLSourceControl_DDLTrigger to the server. The trigger detects when somebody tries to edit a locked object.
The script also creates the database Redgate with the schema SQLSourceControl. This contains:
- the table SQLSourceControl.LockedObjects, to store locks on objects
- the function SQLSourceControl.GetLockedObjects, to retrieve locked objects
- the function SQLSourceControl.IsObjectLocked, to check if objects are locked
- the stored procedure SQLSourceControl.LockObject, to lock objects
- the stored procedure SQLSourceControl.UnlockObject, to unlock objects
To set up object locking from SQL Source Control
- In the Locking tab, click Open setup script.
- Click Run script.
The script opens in a new Management Studio query window. - Close any other query windows that use the RedGate database.
- Run the script.
Object locking is set up for the server.
Required privileges
To run the setup script, you need these database privileges:
CREATE USER
CREATE ROLE
GRANT ANY PRIVILEGE
CREATE ANY TABLE
CREATE ANY PROCEDURE
You don't need these privileges to lock and unlock objects, but you do need permission in the RedGate database to EXECUTE
the following procedures/functions:
SQLSourceControl.LockObject
SQLSourceControl.UnlockObject
SQLSourceControl.LockedObjects
SQLSourceControl.IsObjectLocked