Table of contents
1.
Introduction
2.
Database
3.
CREATE
3.1.
Syntax
3.2.
Example
4.
SELECT
4.1.
SHOW
4.1.1.
Syntax
4.1.2.
Example
4.2.
USE
4.2.1.
Syntax
4.2.2.
Example
5.
DROP
5.1.
Syntax
5.2.
Example
6.
Frequently Asked Questions
6.1.
List some of the data types in SQL. 
6.2.
What is a Primary Key in SQL?
6.3.
Is there any specific query to find the absolute value of a number using numerical expressions?
6.4.
What is DBMS?
6.5.
What are the various operators used with the SELECT statement?
7.
Conclusion
Last Updated: Mar 27, 2024
Easy

CREATE, SELECT, and DROP Database

Author Sagar Mishra
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hey Ninjas, you must be familiar with the term database if you are from a coding background. Everything in a database starts with creating a database. But how can we create a database, and where can we do the same? Don't worry. Coding Ninjas will help you with this.

CREATE, SELECT and DROP Database

Our today's topic is CREATE, SELECT and DROP Database. Let's start without wasting time. Before moving to our main topic, let's first discuss what a database is.

Database

A database is a collection of data managed in a sequence or structured way. Databases store, analyze, manage, and retrieve information. The information comes from multiple users. There are different types of databases. The databases can be NoSQL, relational, and object-oriented databases. 

We can create our database also, using SQL (Structured Query Language). Let's see how.

CREATE

The CREATE DATABASE statement creates a database where you can define your multiple tables or records. Let's move to the syntax first. Then we will see an example of how we can create a database.

Note: The name of the database is not case-sensitive in Windows, but if you're using a Linux or Unix OS, the name of the database is case-sensitive. However, the SQL keywords don't follow any such rules.

Syntax

CREATE DATABASE databaseName;

Example

Let's say we want to create a database with the name ''CodingNinjas''. To do so, we have to write the below SQL query.

CREATE DATABASE CodingNinjas;

 

Output:

successfull message

Explanation:

After running the above command, you see a message ''1 row(s) affected'' means your database is created successfully. Note that the name of the database must be unique.

SELECT

After creating the database, you can also check if it has been created or not. To do so, we have two queries, that is, SHOW and USE.

SHOW

SHOW command is used to check all the databases present in the server.

Syntax

SHOW DATABASES;

Example

SHOW DATABASES;

 

Output:

select output

 

Explanation:

The SHOW DATABASES command displays all the databases present in the server at the moment. The database we created in the last section is in line 2.

USE

Now, the question is, how can we use our created database to perform operations? So we can follow the below syntax and command to use the created database.

Syntax

USE databaseName;

Example

USE CodingNinjas;

Output:

output

 

Explanation:

After running this query in SQL, we can use any database present in the list.

You can also check if you are in the right database or not. In other words, you can check your current database name in MySQL by using the below query. Let's check.

Query:

SELECT DATABASE();

 

Output:

output

DROP

You can also delete the database after using it. To do this, you can use the DROP statement. The DROP statement is a powerful statement as it is irreversible in nature. The DROP statement deletes the current database along with its tables, index and views. The syntax to drop a database is as follows.

Syntax

DROP DATABASE databaseName;

Example

DROP DATABASE CodingNinjas;

 

Output:

successfull message

Explanation:

After executing the above query, the database will be deleted. To verify if the database is deleted or not, we can use the SHOW statement. Let's check it out.

Query:

SHOW DATABASES;

 

Output:

DROP statement

As you can see, CodingNinjas is not present in the database list. Hence, the database is deleted successfully.

Also see,  TCL Commands in SQL and SQL EXCEPT

Frequently Asked Questions

List some of the data types in SQL. 

Char(size), Varchar(length), Text, and Integer are some of the data types in SQL.

What is a Primary Key in SQL?

The PRIMARY KEY constraint uniquely identifies each row in a table. It contains an implied NOT NULL condition and must include UNIQUE data.

Is there any specific query to find the absolute value of a number using numerical expressions?

The answer is yes, we use ABS(number) that returns the absolute value of the given number, and with the absolute value, we mean the magnitude part of a number.

What is DBMS?

DBMS (Database Management System) is software that helps you to organize (create, retrieve, update, and manage) data in a database.

What are the various operators used with the SELECT statement?

The logical, comparison and arithmetic operators are some examples of the operators that we can use with the SELECT statement.

Conclusion

This article discusses the topic ''CREATE, SELECT and DROP Database'' in detail. We have seen the definition of a database. Along with this, we saw CREATE, SELECT, and DROP statements with syntax and examples.

We hope this blog has helped you enhance your knowledge of CREATE, SELECT and DROP Database. If you want to learn more, then check out our articles.

 

 

And many more on our platform Coding Ninjas Studio.

Refer to our Guided Path to upskill yourself in DSACompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio!

But suppose you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundles for placement preparations.

However, you may consider our paid courses to give your career an edge over others!

Happy Learning!

Live masterclass