Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


comparing physcial file name of the database


comparing physcial file name of the database

Author
Message
sps-554505
sps-554505
Valued Member
Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)

Group: General Forum Members
Points: 67 Visits: 224
hi,

Iam using below query to compare the physical location specified,but it is not showing the correct result and as the sys.files it is in diffrent

Is there any other method to compare
as per the structure all my data folders to be in E:drive
asnd log will be in f drive
i want to know which db is not following the correct structure

print('Filename')
exec('use['+@database_name+']
insert #file_check
select '''+@database_name+''',
(select filename from sys.sysfiles where fileid =1 and filename not like ''H:\MSSQL\'+@database_name+'\DATA\'+@database_name+'_Data.mdf''),
(select filename from sys.sysfiles where fileid =2 and filename not like ''I:\MSSQL\'+@database_name+'\LOG\'+@database_name+'_Log.ldf'')
from sys.sysfiles;')

Is there any other method to find out,this is working for some databases
some databases it is not

it is checking Sys.files table and the entire string is matching only it displays the correct result.

Is sys.master files can be used for this

Or please let me know the best method to find out the wrong structure.
Madhivanan-208264
Madhivanan-208264
Old Hand
Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)

Group: General Forum Members
Points: 337 Visits: 476
This may help you

declare @files table(dbname varchar(100), filename varchar(1000))
insert into @files
exec sp_msforeachdb 'select ''?'', filename from ?..sysfiles'
select dbname,min(left(filename,1)),max(left(filename,1)) from @files
group by dbname
having min(left(filename,1))<>'E' or max(left(filename,1))<>'F'



Note that sp_msforeachdb is undocumented which you can simulate using
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/05/13/simulating-undocumented-procedures.aspx



Madhivanan

Failing to plan is Planning to fail
Perry Whittle
Perry Whittle
SSCrazy Eights
SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)

Group: General Forum Members
Points: 8853 Visits: 16589
to get a list of database and filenames use

select name, fileid, filename from sys.sysaltfiles

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
sps-554505
sps-554505
Valued Member
Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)

Group: General Forum Members
Points: 67 Visits: 224
hi,
i need to display which database is not following the correct path,
as per the code i have written it should be that location,what iw ant is it should display if it is not matching
sps-554505
sps-554505
Valued Member
Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)

Group: General Forum Members
Points: 67 Visits: 224
hi,

thanks,my code is getting me the result in coupel of instances,onely few instances ,sys.files filename location is stored as case sensitive,that is why it is giving error messge,

is there any method to modify my code and get the result,i need to check all db,if it is not macthcing with the format specified,
i should get the result of databases which is not correct as per the folder structure..
MANU-J.
MANU-J.
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1716 Visits: 8766
Try this:

DECLARE @database_name SYSNAME
DECLARE @iRowCount INT
DECLARE @t_TableNames_Temp TABLE
(table_name SYSNAME)
drop table #file_check
create table #file_check(DBName sysname,MDFFile sysname,LDFFile sysname)

INSERT @t_TableNames_Temp
SELECT name
FROM SYSDATABASES
WHERE name not in ('pubs','northwind','tempdb')
ORDER BY name
--Getting row count from table
SELECT @iRowCount = COUNT(*) FROM @t_TableNames_Temp
WHILE @iRowCount > 0
BEGIN
SELECT @database_name = table_name from @t_TableNames_Temp
exec('use['+@database_name+']
insert #file_check
select '''+@database_name+''',
(select rtrim(filename) from sysfiles where fileid =1 and filename not like ''H:\MSSQL\'+@database_name+'\DATA\'+@database_name+'_Data.mdf''),
(select rtrim(filename) from sysfiles where fileid =2 and filename not like ''I:\MSSQL\'+@database_name+'\LOG\'+@database_name+'_Log.ldf'')
from sysfiles;')
DELETE FROM @t_TableNames_Temp WHERE @database_name = table_name
SELECT @iRowCount = @iRowCount - 1
END
Select * from #file_check
SET NOCOUNT OFF

HTH
MJ
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5697 Visits: 25280
Shine.mm If this copied correctly
(select filename from sys.sysfiles where fileid =1 and filename not like ''H:\MSSQL\'+@database_name+'\DATA\'+@database_name+'_Data.mdf''),

You have a EXTRA ' between like and and the drive letter H and after the _Data.mdf Modifiying your code to eliminate those additional characters

(select filename from sys.sysfiles where fileid =1
and filename not like ('H:\MSSQL\'+@database_name+'\DATA\'+@database_name+'_Data.mdf'))
does indeed generate a return.
sys.files filename location is stored as case sensitive,

I have tested the following 2 select statements and they show that the filename entry in sys.sysfiles is NOT case sensitive.

SELECT fileid, name
FROM sys.sysfiles
WHERE filename NOT LIKE ('C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\TIPSnTRICKS_Data.MDF')

SELECT fileid, name
FROM sys.sysfiles
WHERE filename NOT LIKE ('c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\tipsntricks_data.mdf')

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search