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:
- The database we want to create should be a simple and unique name, which can be easily identified.
- Database name should be no more than 128 characters.
- Database name cannot have space, but they can use underscores.
- It is necessary that the user must have admin privileges to create a new database.
Example:
SQL
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
It will show the list of all the databases which are present in the SQL server till then.
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
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
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
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