SQLTeam.com | Weblogs | Forums

Database Name


#1

how do I retrieve the database name from the database itself

ELSNODE_51cdca37eb244029b9302a6260b125c1 is the database in SQL in our program we give it a Name I need to how to do a query for that name.


#2

One way:
SELECT DB_NAME()


#3

I need to send you a picture of what I mean, this forum will not let me, is there some other way I can contact you

greg


#4

the database SQL Name is: ELSNODE_d5c7f2aea2c54cd1b55fae4a6b69674c within it there is the name from our program called advantage, that is what I need to retrieve


#5

There is a table - somewhere - that stores that information. You need to find that table and query it to return the name.


#6

how do I find the table?


#7
select *
  from sys.databases d
  
  where name = 'advantage'

??


#8

If the column name is 'database_name':

Select object_name(object_id) From sys.columns Where name = 'database_name';


#9

SELECT * FROM sys.database_principals this will give you all the name of dB on that server.


#10

@gregoryjcolden,
The system view sys.databases will have the name of every database on the server. Is that what you are looking for?
@Pasi,
The system view sys.database_principals is data about database users and roles.