===============================================================================
  SQL: MS SQL Commands             15-APR-11                     Matt Borland
===============================================================================

  Creating a unique index:

    create unique index SiteAddressIdUniq on Site (AddressId);

  Adding a named foreign key:

    alter table Service add constraint FK_Service_CapabilityId foreign key (CapabilityId) references Capability (CapabilityId);

  Making a column NULL/NOT NULL:

    alter table Service alter column CapabilityId int NOT NULL;

  Dropping an index:

    drop index Authority.AuthorityContactIdUniq;

  Dropping a column:

    alter table Authority drop column ContactListId;
	
  Finding all indexes:

    select name from sysindexes order by name;

  Finding all constraints:

    select
      o1.name as Referencing_Object_name
      , c1.name as referencing_column_Name
      , o2.name as Referenced_Object_name
      , c2.name as Referenced_Column_Name
      , s.name as Constraint_name
    from sysforeignkeys fk
      inner join sysobjects o1 on fk.fkeyid = o1.id
      inner join sysobjects o2 on fk.rkeyid = o2.id
      inner join syscolumns c1 on c1.id = o1.id and c1.colid = fk.fkey
      inner join syscolumns c2 on c2.id = o2.id and c2.colid = fk.rkey
      inner join sysobjects s on fk.constid = s.id

  Renaming all constraints (by getting SQL):

    select
      'exec sp_rename ''' + Constraint_name + ''', ''FK_' + Referencing_Object_name + '_' + referencing_column_Name + ''', ''OBJECT'';'
    from ( [sql above] )x;