all groups > sql server programming > june 2006 >
You're in the

sql server programming

group:

Test if log file exists


Re: Test if log file exists Stu
6/24/2006 6:34:35 PM
sql server programming:
There are two ways to answer this, and it depends on what you are
trying to do. If a database is already registered and running on a
server, you can look in the sysfiles table of that database. However,
if you are trying to create a database, and you want to know if those
physical files already exist with those names, then you'll need to use
the CLR (if SQL 2005) or use xp_cmdshell to return the results from a
batch file. I'm not sure if that will work; we disable xp_cmdshell in
our shop.

Stu


[quoted text, click to view]
Re: Test if log file exists oj
6/24/2006 6:49:20 PM
you can use undoc xp_fileexist

e.g.
declare @i int,@file sysname
set @file='c:\windows\win.ini'
exec master..xp_fileexist @file,@i out
select case when @i=1 then @file+' exists' else @file+' does not exist' end

--
-oj



[quoted text, click to view]

Test if log file exists scott
6/24/2006 7:02:01 PM
Is there a way to test if a log physical exists? Below is some code I'd like
to expand to test if @physNameLog exists, and then return a 1 or 0 depending
on the test result.

Any help?


CODE *********************

use master

DECLARE @dbName sysname

DECLARE @physName nvarchar(260), @physNameLog nvarchar(260)

SET @dbname = 'myDB'

SET @physname = 'E:\data\sql_data\myDB_Data.MDF'

SET @physNameLog = REPLACE(@physname,'_data.mdf','_log.ldf')

PRINT @physNameLog

Re: Test if log file exists Tony Rogerson
6/25/2006 12:00:00 AM
Check out http://www.databasejournal.com/features/mssql/article.php/3492046

--
Tony Rogerson
SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a SQL
Server Consultant
http://sqlserverfaq.com - free video tutorials


[quoted text, click to view]

AddThis Social Bookmark Button