Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Alter Database with variable Expand / Collapse
Author
Message
Posted Thursday, April 30, 2009 7:24 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, June 12, 2009 8:16 AM
Points: 38, Visits: 129
Thank you for your hints.
I also think now that it is not good to shrink the transcation log to 1MB.
Although the recovery mode is set to simple (so only the last transactions is stored in the transaction log),
the growth of the transaction log is an expensive operation.
But, why should the transaction log size set to 10% of the database size?
Has someone experiences which is a good value in simple recovery mode?

Regards,
Post #707669
Posted Thursday, April 30, 2009 5:42 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Tuesday, November 17, 2015 2:31 AM
Points: 512, Visits: 615
There are no definitive rules on how you should size the database log file. If I may bore you with my past, back in 1993 I was sent off to Sybase to learn about Sybase System 10. As we all know Sybase and SQL Server are one and the same (poetic licence now I feel) and back then Sybase were saying that, as a good starting point, the log file should be 20% of the size of the database or twice the size of the largest table on which you might perform a single update which hits every row.

But really it depends on how your database is used. One of the databases I look after has data files totalling 1.5TB but the log file is sized at 5GB which is roughly 3%.

Mike
Post #708195
Posted Friday, October 18, 2013 12:44 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Yesterday @ 7:40 AM
Points: 1, Visits: 52
Sometimes you need to change all db's from full to simple in a second environment, where log room is scarce or you are just testing.

Select 'Alter Database ['+name+'] Set Recovery simple with no_wait'
from sys.databases
where recovery_model_desc like 'full' and database_id > 4

Will generate sql's to alter your user db's ( > 4) to simple, but won't run them. You can pick and execute them with cut and paste.

-007sql
Post #1506300
Posted Thursday, March 31, 2016 2:06 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, April 17, 2016 5:07 AM
Points: 1, Visits: 4
Step1: Create an VIEW for generating the offline DBs command for selected DBs

create view DBOfflineView as
select 'alter database'+ ' '+name+' '+'set offline with rollback immediate' as command
from sys.databases
where name not in ('master','model','msdb','tempdb')
--Note: Here you can as per your requirement.For alter the Dbs to simple use,

select 'alter database'+ ' '+name+' '+'set recovery simple' as command
from sys.databases
where name not in ('master','model','msdb','tempdb')

Step2: Select from the View to see the output first

select Command from DBOfflineView



Step3: Create cursor for executing the Command.


DECLARE @OfflineCommand VARCHAR(500) --set offline command
DECLARE db_cursor CURSOR FOR
select Command from DBOfflineView
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @OfflineCommand

WHILE @@FETCH_STATUS = 0
BEGIN

exec(@OfflineCommand)

FETCH NEXT FROM db_cursor INTO @OfflineCommand
END

CLOSE db_cursor
DEALLOCATE db_cursor

/*
Note:
This is how you can put the selected databases offline.
Like this,you can make your own code as per requirement.
Post #1773763
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse