Database in SQL

A database is a structured collection of data that is organized in a way that allows for efficient storage, retrieval, and manipulation of information.

Note: SQL is not case sensitive.

How to create a Database in SQL? The CREATE DATABASE statement creates the database in SQL. Syntax create database <Database_Name>;
In this syntax, <Database_Name> specifies the name of the database which we want to create in the system.

Following are the most important points which are required to learn while creating a database:

Example:

SQL

create database ashish;

When we run the above query, it creates the database with name ashish in the system.

We can also check the above-created Database using the query given below:

SQL

show databases;

It will show the list of all the databases which are present in the SQL server till then.

Database in SQL

SQL does not allow developers to create the database with the existing database name. Suppose if we want to create another database with name ashish in the same database system, then the Create Database statement will show the following error in the output:

Error

Can't create database 'ashish'; database exists

Drop database Query We can delete the existing database by using the drop database. It removes the database and all contents inside it. SQL Syntax drop database <Database_Name>; Example:

SQL

drop database ashish;

The above example deletes the ashish database from the system.

USE Query Suppose database users and administrators want to perform some operations on tables, views, and indexes on the specific existing database in SQL. Firstly, they must select the database on which they want to run the database queries. SQL Syntax USE <database_name>; Example:

SQL

USE ashu;

This example uses the ashu database.

SELECT DATABASE() The SELECT DATABASE() function in SQL is used to return the name of the current database. This can be useful when you need to confirm which database context you are operating in.

SQL

SELECT DATABASE();