Click here to Skip to main content
15,910,661 members
Home / Discussions / Database
   

Database

 
GeneralRe: Defragmentation Problem Pin
Eddy Vluggen18-Mar-09 6:08
professionalEddy Vluggen18-Mar-09 6:08 
GeneralRe: Defragmentation Problem Pin
Aman786Singh18-Mar-09 6:40
Aman786Singh18-Mar-09 6:40 
GeneralRe: Defragmentation Problem Pin
Eddy Vluggen18-Mar-09 9:46
professionalEddy Vluggen18-Mar-09 9:46 
Questionhow to reduce the log file of a large database? Pin
ma.amer17-Mar-09 9:28
ma.amer17-Mar-09 9:28 
AnswerRe: how to reduce the log file of a large database? Pin
Natza Mitzi17-Mar-09 10:05
Natza Mitzi17-Mar-09 10:05 
GeneralRe: how to reduce the log file of a large database? [modified] Pin
ma.amer17-Mar-09 10:19
ma.amer17-Mar-09 10:19 
GeneralRe: how to reduce the log file of a large database? Pin
scottgp17-Mar-09 14:28
professionalscottgp17-Mar-09 14:28 
AnswerRe: how to reduce the log file of a large database? Pin
Aman786Singh17-Mar-09 19:41
Aman786Singh17-Mar-09 19:41 
run this if you are working in sql 2005 server.



but for this u need to make your database offline first and then run this code.

--INF: How to Shrink the SQL Server 7.0 Transaction Log
-- SQL7 http://support.microsoft.com/support/kb/articles/q256/6/50.asp?id=256650&SD
-- SQL7 http://www.support.microsoft.com/kb/256650
-- SQL2000 http://support.microsoft.com/kb/272318/en-us
-- SQL2005 http://support.microsoft.com/kb/907511/en-us
-- select db_name()
-- select * from sysfiles

-- THIS SCRIPT IS NOT INTENDED FOR SCHEDULED USAGE !! READ BOL and the urls !!

SET NOCOUNT ON
DECLARE @LogicalFileName sysname,
@MaxMinutes INT,
@NewSize INT


-- *** MAKE SURE TO CHANGE THE NEXT 3 LINES WITH YOUR CRITERIA. ***

SELECT @LogicalFileName = 'Test_Log', -- Use sp_helpfile to identify the logical file name that you want to shrink.
@MaxMinutes = 10, -- Limit on time allowed to wrap log.
@NewSize = 305 -- in MB

-- Setup / initialize
DECLARE @OriginalSize int
SELECT @OriginalSize = size -- in 8K pages
FROM sysfiles
WHERE name = @LogicalFileName
SELECT 'Original Size of ' + db_name() + ' LOG is ' +
CONVERT(VARCHAR(30),@OriginalSize) + ' 8K pages or ' +
CONVERT(VARCHAR(30),(@OriginalSize*8/1024)) + 'MB'
FROM sysfiles
WHERE name = @LogicalFileName
CREATE TABLE DummyTrans
(DummyColumn char (8000) not null)


-- Wrap log and truncate it.
DECLARE @Counter INT,
@StartTime DATETIME,
@TruncLog VARCHAR(255)
SELECT @StartTime = GETDATE(),
@TruncLog = 'BACKUP LOG ' + db_name() + ' WITH TRUNCATE_ONLY'
-- Try an initial shrink.
DBCC SHRINKFILE (@LogicalFileName, @NewSize)
EXEC (@TruncLog)
-- Wrap the log if necessary.
WHILE @MaxMinutes > DATEDIFF (mi, @StartTime, GETDATE()) -- time has not expired
AND @OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName) -- the log has not shrunk
AND (@OriginalSize * 8 /1024) > @NewSize -- The value passed in for new size is smaller than the current size.
BEGIN -- Outer loop.
SELECT @Counter = 0
WHILE ((@Counter < @OriginalSize / 16) AND (@Counter < 50000))
BEGIN -- update
INSERT DummyTrans VALUES ('Fill Log') -- Because it is a char field it inserts 8000 bytes.
DELETE DummyTrans
SELECT @Counter = @Counter + 1
END -- update
EXEC (@TruncLog) -- See if a trunc of the log shrinks it.
END -- outer loop
SELECT 'Final Size of ' + db_name() + ' LOG is ' +
CONVERT(VARCHAR(30),size) + ' 8K pages or ' +
CONVERT(VARCHAR(30),(size*8/1024)) + 'MB'
FROM sysfiles
WHERE name = @LogicalFileName
DROP TABLE DummyTrans
PRINT '*** Perform a full database backup ***'
SET NOCOUNT OFF
GeneralRe: how to reduce the log file of a large database? Pin
ma.amer18-Mar-09 2:01
ma.amer18-Mar-09 2:01 
QuestionChecking positive number Pin
Pankaj Garg17-Mar-09 8:40
Pankaj Garg17-Mar-09 8:40 
AnswerRe: Checking positive number Pin
Rob Graham18-Mar-09 2:19
Rob Graham18-Mar-09 2:19 
AnswerRe: Checking positive number Pin
Eddy Vluggen18-Mar-09 2:38
professionalEddy Vluggen18-Mar-09 2:38 
QuestionGranting rights Pin
Aman786Singh17-Mar-09 2:23
Aman786Singh17-Mar-09 2:23 
Questioncreating hyperlink in SQL Server2005 Pin
Saleem Tahiri17-Mar-09 0:51
Saleem Tahiri17-Mar-09 0:51 
AnswerRe: creating hyperlink in SQL Server2005 Pin
Ashfield17-Mar-09 2:21
Ashfield17-Mar-09 2:21 
AnswerRe: creating hyperlink in SQL Server2005 Pin
ed575627-Mar-09 6:01
ed575627-Mar-09 6:01 
QuestionIssue with VS 2005 Pin
p_196016-Mar-09 22:39
p_196016-Mar-09 22:39 
AnswerRe: Issue with VS 2005 Pin
itsravie16-Mar-09 23:38
itsravie16-Mar-09 23:38 
Questionms access connection string Pin
vishakpb16-Mar-09 21:32
vishakpb16-Mar-09 21:32 
AnswerRe: ms access connection string Pin
Eddy Vluggen16-Mar-09 21:55
professionalEddy Vluggen16-Mar-09 21:55 
AnswerRe: ms access connection string Pin
itsravie16-Mar-09 23:41
itsravie16-Mar-09 23:41 
Questionsaving data Pin
neoghy16-Mar-09 4:08
neoghy16-Mar-09 4:08 
AnswerFor Oracle Pin
David Mujica16-Mar-09 4:57
David Mujica16-Mar-09 4:57 
GeneralRe: saving data Pin
RussellT5-Jun-09 10:07
professionalRussellT5-Jun-09 10:07 
QuestionSql Restore Error Pin
kankeyan16-Mar-09 3:53
kankeyan16-Mar-09 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.