Archive

Archive for the ‘SQL Server’ Category

SQL Server: Stop trace using SQL Command

January 15th, 2009 2 comments

Today I started SQL Profiler and paused it. After some time, none of the buttons were enabled. I can neither resume nor stop the trace. Here are the sql commands that I finally found to stop the trace.

1) Get the trace id

SELECT * FROM ::fn_trace_getinfo(default) WHERE property = 2;

2) Stop trace

DECLARE @TraceID int
SET @TraceID = ?
EXEC sp_trace_setstatus @TraceID, 0
EXEC sp_trace_setstatus @TraceID, 2
Categories: SQL Server Tags: ,

Change Database Name in SQL Server

December 23rd, 2008 1 comment

SQL Server Enterprise Manager does not let you change your database name once you create it. If you want to change your database name, you may have to manually run the following script to change it. First of all you have to login to SQL Server using osql command line utility. Once you are in, fire following commands to rename database.

ALTER DATABASE OldName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
go

sp_renamedb 'OldName', 'NewName'
go

ALTER DATABASE NewName SET MULTI_USER
go
Categories: SQL Server Tags: , , ,