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] scott wrote:
> 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
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] "scott" <sbailey@mileslumber.com> wrote in message
news:u9wP0o%23lGHA.464@TK2MSFTNGP05.phx.gbl...
> 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
>
>
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