EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign up
Home Software Development Software Development Tutorials MariaDB Tutorial MariaDB Select Database

MariaDB Select Database

Sohel Sayyad
Article bySohel Sayyad
Priya Pedamkar
Reviewed byPriya Pedamkar

Updated June 2, 2023

MariaDB Select Database

Definition of MariaDB Select Database

MariaDB provides different clauses to the user to perform a different operation as per requirement, so select one type of clause. Basically select is used to retrieve the data from the database server. When we use the select database command it retrieves the current database name that is in use, which means it is useful to check the current database name. Selecting a database is another concept when we need to select a database at that time, we use the USE keyword to select a specific database. So selecting and using a database is totally different, but it performs similar functions related to the database. We can perform different operations on databases by using select clauses.

ADVERTISEMENT
Popular Course in this category
MARIADB Course Bundle - 5 Courses in 1

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

select database();

Explanation:

In the above syntax, we use the select clause with a database function, as shown in the above statement, here select clause retrieves the current database name from the MariaDB server and the database function is used to indicate the name of the database.

How to Select Database in MariaDB?

Let’s see how the select database works in MariaDB as follows.

The select clause is used to retrieve data, or we can say records, table, and database from the MariaDB server means that we can use a select clause as per user requirement. Each select expression shows what type of data we need to retrieve from the database or server.

After execution of the select database command, it returns the current database name that is the default database name otherwise, it returns the null.

We can also use SCHEMA () as a synonym for the DATABASE () both commands perform the same function.

Examples

Let’s see the different examples of select databases as follows.

First, connect to the MariaDB server using the client program, so we required a password. Then use the following statement to see the current database.

select database();

Explanation:

In the above example, we use a select clause followed by a database function, as shown in the above statement. Suppose users need to see the current database name so that time we can use the above statement and return the current database name. The final output of the show databases queries we illustrate by using the following snapshot.

MariaDB Select Database 1

Example: If we don’t use any database.

select database();

Explanation:

In the above example, we use a select clause followed by a database function, as shown in the above statement. Suppose the user wants to see the name of the current database so that times we can use the above statement but return the null value because we can’t use any database. The final output of the show databases queries we illustrate by using the following snapshot.

MariaDB Select Database 2

Example

Suppose users need to switch to another database and then need to check the current database name at that time, we use the following statement.

First, we need to use the different database as follows

First, we need to check all available databases from the server as follows.

show databases;

Explanation:

By using the above statement, we list all databases from the MariaDB server and then use any of them. The final output of the show databases queries we illustrate by using the following snapshot.

MariaDB Select Database 3

Syntax:

use database name;

Explanation:

In the above syntax, the use database command is used to select a specific database from the MariaDB server, here, the database name is used to specify the database name we need to use as the current database.

Example

use demo;

Explanation:

With the help of the above statement, we switch the database, which means one database to another database; here demo is the database name that we need to use for our workspace. The final output of the show databases queries we illustrate by using the following snapshot.

MariaDB Select Database 4

After switching databases, we again perform a select database command as follows.

select database();

Explanation:

See hereafter switching the database name, we execute the select database () command to check the current database name, here, we changed the database sample to demo. The final output of the show databases queries we illustrate by using the following snapshot.

database

Now see how the schema works as follows.

select schema();

Explanation:

In the above example, we use a select clause to fetch our workspace’s default database or current database. Here select clause followed by the schema keyword works similarly to a select database of our current workspace. The final output of the show databases queries we illustrate by using the following snapshot.

schema sample

Now let’s see a different example of a select database as follows.

Suppose we created a new database name office, and we need to use it for the current workspace, so first, we need to create the database by using the following statement as follows.

create database office;

Explanation:

In the above example, we used to create a database statement to create a new database here, we created a new database name, office. The final output of the show databases query we illustrate by using the following snapshot.

create DB Office

Now see the created database by using the following statement as follows.

show databases;

Explanation:

In this example, we use the show databases command to list all databases from the MariaDB server. The final output of the show databases queries we illustrate by using the following snapshot.

database 1

Now use the created database for our current workspace by using the following statement as follows.

use office;

Explanation:

When executing the above statement, it shows the database is changed because of the use command. The final output of the show databases queries we illustrate by using the following snapshot.

database changed

Finally, we can now see the current database name by using the following statement.

select database();

Explanation:

When we execute the above statement, which contains the select clause followed by the database keyword, it is used to see the current database of our workspace. The final output of the show databases queries we illustrate by using the following snapshot.

database office

Conclusion

We hope from this article you have understood about the MariaDB select database. This article taught us the basic syntax of special databases and see different examples of select databases. This article taught us how and when to use MariaDB select database.

Recommended Articles

We hope that this EDUCBA information on the “MariaDB Select Database” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. MariaDB AUTO_INCREMENT
  2. MaxScale in MariaDB
  3. MariaDB UPDATE 
  4. MariaDB Commands
ADVERTISEMENT
MICROSOFT POWER BI Course Bundle - 8 Courses in 1
34+ Hours of HD Videos
8 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
CYBER SECURITY & ETHICAL HACKING Course Bundle - 13 Courses in 1 | 3 Mock Tests
64+ Hours of HD Videos
13 Courses
3 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
63+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
KALI LINUX Course Bundle - 6 Courses in 1
20+ Hours of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Footer
About Us
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Blog as Guest
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW