Kayıtlar

Database etiketine sahip yayınlar gösteriliyor

Truncate Logfile in SQL Server

Using the code Step 1. Copy/type the below given SQL. Step 2. Change @DBName to < Database Name>, @DBName_log to Step 3. Execute the SQL. ALTER DATABASE @DBName SET RECOVERY SIMPLE WITH NO_WAIT DBCC SHRINKFILE(@DBName_log, 1) ALTER DATABASE @DBName SET RECOVERY FULL WITH NO_WAIT GO In SQL Server data is stored using two physical files:  (.mdf)  extension  which contains the data.  (.ldf) extension which contains log. Log file size increases very rapidly and depend on the operation performed on the data. After a long time period this file becomes too large. When log file is too large it takes time to perform some operations like ( attach , de-attach, backup, restore … etc ). 

SQL: Drop / Kill Database Connections

If you need to drop database connections for a specific database, go read on..  This has been tested for Microsoft SQL Server 2005 and Microsoft SQL Server 2008. Code starts here use master declare @vcdbname varchar(50) /* @vcdbname => set it to the database you want the connections to be dropped.. */ Set @vcdbname = ‘cxnIM’ set nocount on declare Users cursor for select spid from master..sysprocesses where db_name(dbid) = @vcdbname declare @spid int, @str varchar(255) open users fetch next from users into @spid while @@fetch_status <> -1 begin    if @@fetch_status = 0    begin    print @spid       set @str = ‘kill ‘ + convert(varchar, @spid)       exec (@str)    end    fetch next from users into @spid end deallocate users and ends here