A quick script for database permissions

11 October 2011

During SQL Saturday 92 I was asked about how to do easily manage permissions. I am assuming that systems are using application-specific database roles. Database roles are great because they are login-independent and can work in any environment.

I have found that two approaches tend to work quite well.

  1. Script out the necessary permissions per object (table, view, stored procedure). Put it into the same file as the object definition itself, in source control
  2. Have a 'complete list' script that lists all permissions, and applies any updates or changes.

I have written a sample 'complete list' script, below, that defines permissions in XML, which can then be audited or applied to a database.  

Complete List.sql

Permalink

Database Development - Keep It Agile, Not Fragile

08 October 2011

On October 8, 2011, I presented a session on agile database development at SQL Saturday 92. The goal was to help people understand that agile database development makes your business more successful, if you adopt best practices and handle the different risks.

My presentation materials are below. Please note that the demo scripts are designed to work with the AdventureWorks database. Some of them (the design demos) will work in almost any database. Others (the unit test demos) are schema specific.

Slide Deck

DesignBestPractices.sql

This includes several useful integrity checks, such as identifying the following:

  • Possible missing foreign keys
  • Foreign keys with datatype mismatches
  • Foreign keys without indexes
  • Tables without primary keys
  • The number of stored procedures, views, and functions per table

DeploymentBestPractices.sql

This includes several deployment best practices, including:

  • Re-runnable alter-table scripts
  • Re-runnable index scripts
  • Best practices for changing stored procedures, views, functions, and triggers
  • Example versioning of a database
  • Doing quick verification tests of deployed DB code
  • Examples of how to deprecate tables, and then undo your work if you need to roll back

TestingBestPractices.sql

This includes several examples of how to unit test database objects, including:

  • Unit Testing a Stored Procedure
  • Unit Testing a table schema
Permalink