Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Shrink logs
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01411487
Message ID:
01411506
Vues:
36
Hi Boris,

Looks like IF ? in condition is ignored.

I tried
declare @Str varchar(800)

set @Str = 'IF ''?'' NOT IN (''master'', ''tempdb'', ''model'', ''msdb'')' + CHAR(13) + 'BEGIN ' + CHAR(13) +
'ALTER DATABASE ? SET RECOVERY SIMPLE' + CHAR(13) + 'DBCC SHRINKFILE (N''?_log'',0,TRUNCATEONLY)' + char(13) + 'END'

execute sp_msForEachdb @Str
and got
Msg 5058, Level 16, State 1, Line 1
Option 'RECOVERY' cannot be set in database 'tempdb'.
Msg 8985, Level 16, State 1, Line 1
Could not locate file 'ReportServer$IOTECHSQL2008_log' for database 'Test' in sys.database_files. The file either does not exist, or was dropped. 
Msg 8985, Level 16, State 1, Line 1
Could not locate file 'ReportServer$IOTECHSQL2008TempDB_log' for database 'Test' in sys.database_files. The file either does not exist, or was dropped. 
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
>The same way :-):
>
>sp_MSForEachDb 'declare @LogFile nvarchar(2000)
>                declare @ExeString nvarchar(2000)
>                IF ''?'' NOT IN (''master'', ''tempdb'', ''model'', ''msdb'')
>                   BEGIN
>                      USE [?]
>                      SELECT @LogFile = dbo.sysaltfiles.name
>                             FROM master.dbo.sysdatabases
>                      INNER JOIN dbo.sysaltfiles ON master.dbo.sysdatabases.dbid = dbo.sysaltfiles.dbid
>                      WHERE (master.dbo.sysaltfiles.fileid = 1) AND (master.dbo.sysdatabases.name = ''?'')
>                      ALTER DATABASE [?] SET RECOVERY SIMPLE
>                      SET @ExeString = ''DBCC SHRINKFILE ('' + QUOTENAME(@LogFile) + '', 1)''
>                      EXEC (@ExeString)
>                    END'
>
>Check for errors, because I wrote this directly here and didn't test it :-)
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform