I want to find which database is querying from, here is my output:
EXEC sp_example @stat = N'SELECT stat FROM [dbo].[statsUSers] AS [UserStats];
What I want is like this:
EXEC sp_example @stat=N'SELECT stat FROM [MyOwnDataBase].[statsUSers] AS [UserStats];
I've already tried this tip: SQL Server Profiler - how do I find which database is being connected?
but still it's [dbo] and not showing the name of the database.
Question
How can I access name of database?
I don't want [dbo] changes to something meaningless - I want the actual name of database.
When creating the trace, you can select
Show all columns, which will then display theDatabaseIDandDatabaseNamecolumns.Note that
dbois the schema name, not the database name. There is no option to capture the default schema of the user, this is the one they would refer to if accessing a table likeSELECT * FROM table. To capture the default schema you would instead have to capture theusernamethen work out what the user's default schema is.I would advise you to move away from the essentially deprecated Profiler, to Extended EVents, which provides far more information and puts far less load on the server.
In Extended Events, you can add the
database_namealso.