Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Script Help to add to maintenece plan

Author  Topic 

ajspruit911
Starting Member

3 Posts

Posted - 2008-10-10 : 07:15:04
Hi all

Im reletivly new to SQL and scripting and am having some trouble with a script that i wrote. As per normal most of the individual elements work seperately but they don't work together as a whole.

Aim: Make sure recovery mode is set to simple and shrink transaction log before doing the backup.

The backups are done via SQL Lightspeed with a clean up script to follow.

Script:

declare @dbname varchar(45)
select @dbname = DB_NAME()
print @dbname
use master
ALTER DATABASE @dbname SET RECOVERY SIMPLE
declare @logname varchar(45)
use @dbname
select @logname = rtrim(name) from sysfiles where name like '%log%'
print @logname
dump transaction @dbname with no_log
dbcc shrinkfile (@logname, 2)



Sorry, i know it's messy but i will sort that out later, any assistance on getting this working or a better alternitive would be much appriated.

thanks in advance
AJ

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-10 : 07:27:19
refer below. might be what you're looking for

http://www.sqlservercentral.com/Forums/Topic474775-357-1.aspx
http://sqlblog.com/blogs/tibor_karaszi/archive/2007/09/25/tsql-script-to-do-backup-like-maintenance-plans.aspx
Go to Top of Page
   

- Advertisement -