Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 ******How to select Logical database name*********

Author  Topic 

navmiester
Starting Member

3 Posts

Posted - 2007-07-31 : 20:37:32
Hi how do I select the current logical database name using a select statement.

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-07-31 : 22:47:00
What do you mean logical database name?
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-08-01 : 00:17:38
select db_name()


elsasoft.org
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-08-01 : 11:40:02
This gives you real db name.
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2007-08-02 : 01:56:00
quote:
Originally posted by navmiester

I do not want the dbname of the database I want the logical name. This can be obtained using the FileList only command. However I would like this to be done in a select statement if possible.




are you confusing database name with the logical names of the datafiles?

try the file_name function instead.



-ec
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-08-02 : 22:50:38
Or get them from sys.sysfiles.
Go to Top of Page

navmiester
Starting Member

3 Posts

Posted - 2007-08-09 : 19:43:45
Thank you eyechart, I found the following code on a MSDN site

USE <Database name>
GO
SELECT FILE_NAME(1) AS 'File Name 1', FILE_NAME(2) AS 'File Name 2';
GO

quote:
Originally posted by eyechart

quote:
Originally posted by navmiester

I do not want the dbname of the database I want the logical name. This can be obtained using the FileList only command. However I would like this to be done in a select statement if possible.




are you confusing database name with the logical names of the datafiles?

try the file_name function instead.



-ec

Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-08-09 : 22:41:42
Those are logical file names, not db name.
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2007-08-09 : 23:11:53
quote:
Originally posted by rmiao

Those are logical file names, not db name.




yeah, that is actually what he was looking for.



-ec
Go to Top of Page
   

- Advertisement -