views:

46

answers:

2

I'm trying to shrink the log of a database AND set the recovery to simple, but always there is an error, whatever i try.

USE 4_o5;
GO
ALTER DATABASE 4_o5
SET RECOVERY SIMPLE;
GO
DBCC SHRINKFILE (4_o5_log, 10);
GO

the output of sp_helpfile says that log file is located under (hosted solution):

I:\dataroot\4_o5_log.LDF

please help me perform this operation as the log file got large when importing a lot of data and now this info is no longer needed, have multiple (lots of) backups since then.

the exact error message when performing the query above is:

incorrect syntax near '4'.
RECOVERY is not a recognized SET option.
incorrect syntax near _5_log'.

I am using Visual Studio 2010 (also have SQL Server Express installed locally, SQL Server 2008 proper installed at provider (shared))

thnx a lot

+1  A: 

Try this:

USE [4_o5];
GO
ALTER DATABASE [4_o5] SET RECOVERY SIMPLE;
GO
DBCC SHRINKFILE ([4_o5_log], 10);
GO

Your database name starting with a numeric value is a bit unusual - try putting it in square brackets.

UPDATE: for the DBCC SHRINKFILE, you need the logical name of the log file - that's the name property from the sp_helpfile call. And you also need to put it in square brackets:

USE [4_o5]
GO
DBCC SHRINKFILE ([4_o5_log], 10)
GO
marc_s
yeah, provider requirement for the numeric start.
b0x0rz
now i get a slightly changed error: **incorrect syntax near '4'. incorrect syntax near 'GO'. incorrect syntax near 'GO'.**
b0x0rz
@b0x0rz: sorry, you also need square brackets around the database name in the USE statement.
marc_s
yeah i put them there also - then the error is: **incorrect syntax near 'GO'. incorrect syntax near 'GO'. incorrect syntax near 'GO'.**
b0x0rz
You shouldn't need the `GO` lines
Joe Philllips
The semicolon and GO should be doing the same thing
Joe Philllips
now the error is: **could not locate '4_o5_log' for database '4_o5' in sys.database_files. the file either does not exist, or was dropped.**
b0x0rz
but like i said sp_helpfile shows the file to be there
b0x0rz
+1  A: 

Just do

USE [4_o5] --need brackets with this DB name, as marc_s commented
GO
DBCC SHRINKFILE (2, 10)

DBCC also takes the internal file id number and I see you're having problems separating logical and physical file names... which leads me to assume you don't have multiple log files or NDFs etc and the log file will always be 2

However, why do you want to shrink anyway?

To change recovery model: ALTER DATABASE [4_o5] SET RECOVERY SIMPLE

gbn
yeah, shrink worked with: **USE [4_o5]; DBCC SHRINKFILE (2, 10)** so thank you. can you also maybe please advise on how to set the logging to simple. an the reason has to do with how the provider allocates the space for the database, because it can reach the limit of expansion available - it was very near it. talking with them to upgrade us soon. just had to deal with this first.
b0x0rz
@gbn: the USE won't work if the database name starts with a numerical value - you need to use `USE [4_o5]`
marc_s
@marc_s, @b0x0rz: answer updated
gbn
thank you, everything works now - thank you
b0x0rz