mssql

MSSQL Transaction Log Full

Problem: Occasionally I get the following JDBC error from MSSQL:

The log file for database 'db_example' is full. Back up the transaction log for the database to free up some log space.

Solution:

BACKUP LOG db_example WITH TRUNCATE_ONLY
DBCC SHRINKFILE(db_example_log, 2)

If ‘db_example_log’ is not the logical name of the logfile, the 2nd command will fail. The correct logical name can be found by running the following statements:

USE db_example;
SELECT * FROM sysfiles;

mssql

Comments (0)

Permalink

MSSQL Fix Owner

 For whatever reason, it’s occasionally necessary to change the owner of tables in MSSQL.  In this example, we are changing the owner from “oldowner” to “dbo”:

declare tabcurs cursor
for
   select 'oldowner.' + name
   from sysobjects
   where xtype = 'u' OR xtype = 'v'

open tabcurs
declare @tname nvarchar(517)
fetch next from tabcurs into @tname
while @@fetch_status = 0
begin
   exec sp_changeobjectowner @tname, 'dbo'
   fetch next from tabcurs into @tname
end
close tabcurs
deallocate tabcurs

mssql

Comments (0)

Permalink