Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Alter Database with variable


Alter Database with variable

Author
Message
baumgaertner
baumgaertner
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
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,
Mike_D
Mike_D
Mr or Mrs. 500
Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)

Group: General Forum Members
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
mcdbagds
mcdbagds
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 54
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
mishradharmesh.2192
mishradharmesh.2192
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 5
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search