Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2003
    Posts
    20

    Unanswered: How to check which one is the current databse?

    Which sql can do display the name of the current database in Mysql?? Thnx

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    what is a "current" database?

    imagine you are the mysql database engine, sitting there on the server, minding your own business, responsible for processing the sql that comes in, and for managing all the databases under your control

    now along comes fred and asks, "which one is the current database?"

    what would you say to fred?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2003
    Posts
    20
    "Most database servers, including MySQL, can offer access to more than one database. When a user has opened a connection with a database server and wants, for example, to create new tables or query existing tables, he must specify the database he wants to work with. This is called the current database. There can be only one current database. That means that all SQL statements will be fired at this database." --Quoted from section 4.5 of "Introduction to SQL Mastering the Relational Database Language 4th Edition"

    use Foo -- This sql make Foo the current database.

    So my question is how to display the current database for the user?? Make sense??

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    There is no such thing. The user/logic system has to choose the database. And if that's the case then you already know what it is...

  5. #5
    Join Date
    Jun 2003
    Posts
    20
    What do you mean by "user/logic system"??

    I am accessing MySql server using mysql command line client.

    For example, when you issue a sql to create a table like "create table foo", the server has to know which database is the target. The default is the current database. And you can change the current database using "use dataBaseName" sql statement. This totally makes sense to me.

    Why you guys say there is no such a thing??? I am confused....really
    Last edited by coolioo; 04-13-07 at 10:08.

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    okay, now that we know a little bit more about what you're doing...

    when you issue your very first command in the command line client, if you ever get the error message "No database selected" it is because you haven't used the USE command yet

    so when you use the USE command, that's your current database

    in this case, the "user/logic system" is you

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Check the comments for the USE command at
    http://dev.mysql.com/doc/refman/5.0/en/use.html

    Obviously you can use SELECT database(); to retrieve that information

  8. #8
    Join Date
    Jun 2003
    Posts
    20
    thnx guys for your valuable replies.

    SELECT database(); is the thing I want, thank you shammat

  9. #9
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    shammat, nice one, thanks

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •