Determine what user created objects in SQL Server

If the object was recently created, you can check the Schema Changes History report, within the SQL Server Management Studio, which “provides a history of all committed DDL statement executions within the Database recorded by the default trace”: You then can search for the create statements of the objects. Among all the information displayed, there … Read more

How to find slowest queries

In SQL 2005 you can use management views to find slow running queries. A good script i found a while ago on SQL server performance will help get you started; it lists data with the slowest performing first. SELECT creation_time ,last_execution_time ,total_physical_reads ,total_logical_reads ,total_logical_writes , execution_count , total_worker_time , total_elapsed_time , total_elapsed_time / execution_count avg_elapsed_time … Read more

Is it possible to force row level locking in SQL Server?

You can use the ROWLOCK hint, but AFAIK SQL may decide to escalate it if it runs low on resources From the doco: ROWLOCK Specifies that row locks are taken when page or table locks are ordinarily taken. When specified in transactions operating at the SNAPSHOT isolation level, row locks are not taken unless ROWLOCK … Read more

Return value from exec(@sql)

On the one hand you could use sp_executesql: exec sp_executesql N’select @rowcount=count(*) from anytable’, N’@rowcount int output’, @rowcount output; On the other hand you could use a temporary table: declare @result table ([rowcount] int); insert into @result ([rowcount]) exec (N’select count(*) from anytable’); declare @rowcount int = (select top (1) [rowcount] from @result);