Wednesday, February 20, 2013

Locating users within a DB

exec sp_MSforeachdb 'select ''?'' as Db, * from ?.sys.sysusers where name like ''%SomeUser%'''

Friday, February 15, 2013

Delete duplicates




delete from a
from
dbo.tableWithDupes a
join (
select
ColPrimaryKey
,row_number() over(
partition by AccountId, Col2, Col3 -- these are the unique columns
order by AccountId -- use this to give one record priority over another
) DupeCount
from
dbo.tableWithDupes
) q
on a.ColPrimaryKey = q.ColPrimaryKey
where
q.DupeCount > 1




Tuesday, February 12, 2013


SET STATISTICS IO ON
SET STATISTICS TIME ON
SET STATISTICS PROFILE ON
SET STATISTICS XML ON