hello all,
i was able to get most part working...i took the below article and used it to come up with my strategy of backing up newly created DB that will be scheduled by agent to run every day or so....But when i run the below code i get this error...
fails at this part "backup database @newdb to disk = @loc2;"
Msg 137, Level 16, State 1, Line 21
Must declare the scalar variable "@newdb".
Msg 137, Level 16, State 1, Line 21
Must declare the scalar variable "@LOC2".
http://www.sqlservercentral.com/articles/Administration/trackingdownnewlycreateddatabases/1582/
any help is appreciated....
Use
master
Go
DECLARE
@LOC nvarchar(512) = N'H:\Backup\SQLTEST02\';
DECLARE
@BKP_EXT nvarchar(5);
DECLARE
@retval int;
SET
@BKP_EXT = '.bak';
DECLARE
@newdb table
(
newdb nvarchar(512)
);
DECLARE
@LOC2 table
(
loc2 nvarchar(512)
);
Exec
@retval = sp_track_new_databases
If
(@retval > 0)
insert
into
Select new_db_name
from Last_DB_Track;
select * from @newdb;
insert into @LOC2
select 'backup database ' + new_db_name + ' to disk = ''' + @LOC + new_db_name + '.bak''' from last_db_track;
select * from @LOC2;
backup database @newdb to disk = @loc2;
go