The Wayback Machine - https://web.archive.org/web/20240930194655/https://www.geeksforgeeks.org/sql-create-database/
Open In App

SQL CREATE DATABASE

Last Updated : 08 May, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

SQL CREATE DATABASE statement creates a new database in SQL-based DBMS.

CREATE DATABASE in SQL

The CREATE DATABASE query in SQL is used to create a new database in the database management system. It is also used in MySQL and other relational database management systems (RDBMS) to create databases.

Syntax

The syntax to use the CREATE DATABASE command in SQL is:

CREATE DATABASE database_name;

CREATE DATABASE Examples

Let’s look at examples of how to create a database in SQL and how to verify database creation by listing databases in the server.

Creating Your First SQL Database

To create a new database in SQL we use the CREATE DATABASE command and then we mention the name of the database. Note that blank spaces are not allowed in the name of the database, we can only use underscore (_). 

As an example, we will create a new database with the name “GeeksForGeeks”.

SQL Query:

CREATE DATABASE GeeksForGeeks;

Output

creating new database

Creating a new database

Database Successfully Created!!

List Databases in SQL

Now we will verify whether the new database that we have just created has been successfully added to our system or not. 

We use the SHOW DATABASES command and it will return a list of databases that exist in our system. Now we will look for the name of the database (GeeksForGeeks) that we have just created.

SQL Query:

SHOW DATABASES;

Output

list of databases created

Database successfully created

As we can see the SHOW DATABASE command returned the list of all databases that exist in our system and in that list, the name of the database (GeeksForGeeks) that we have just created has also been added which verifies that the database has been successfully created.

USE Database in SQL

To use a specific database in SQL, we use the USE Statement.

Syntax

The syntax to use a database in SQL is:

USE database_name

Important Points About SQL CREATE DATABASE

  • A CREATE DATABASE statement is used to create a database.
  • A database consists of tables and inside the tables, we store the data.
  • The database name is case-insensitive, so we need to create a unique database name.
  • Keep the limit of database names to 128 characters.

Previous Article
Next Article

Similar Reads

Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
In this article, we will be learning about how to do basic database operations using JDBC (Java Database Connectivity) API in Java programming language. These basic operations are INSERT, SELECT, UPDATE, and DELETE statements in SQL language. Although the target database system is Oracle Database, the same techniques can be applied to other databas
6 min read
Create Database in MS SQL Server
Databases in Microsoft SQL Server are crucial for managing data, categorized into system databases, which are auto-created and user databases, created by users. In this article, We will learn about the basics of system and user databases along with methods for creating and managing them using T-SQL and SQL Server Management Studio (SSMS). Create Da
6 min read
Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
Structured Query Language (SQL): Structured Query Language (SQL) has a specific design motive for defining, accessing and changement of data. It is considered as non-procedural, In that case the important elements and its results are first specified without taking care of the how they are computed. It is implemented over the database which is drive
2 min read
Configure SQL Jobs in SQL Server using T-SQL
In this article, we will learn how to configure SQL jobs in SQL Server using T-SQL. Also, we will discuss the parameters of SQL jobs in SQL Server using T-SQL in detail. Let's discuss it one by one. Introduction :SQL Server Agent is a component used for database task automation. For Example, If we need to perform index maintenance on Production ser
7 min read
SQL vs NO SQL vs NEW SQL
SQL stands for Structured Query Language. Which is based on relational algebra and schema is fixed in this which means data is stored in the form of columns and tables. SQL follows ACID properties which means Atomicity, Consistency, Isolation, and Durability are maintained. There are three types of languages present in SQL : Data Definition Languag
2 min read
SQL Trigger | Book Management Database
Prerequisite - SQL Trigger | Student Database For example, given Library Book Management database schema with Student database schema. In these databases, if any student borrows a book from library then the count of that specified book should be decremented. To do so, Suppose the schema with some data, mysql> select * from book_det; +-----+-----
2 min read
Strategies For Migrating From SQL to NoSQL Database
Migrating from a SQL database to a NoSQL database can be a complex process, but there are several strategies that can be used to make the transition smoother. Here are some common strategies for migrating from SQL to NoSQL: Analyze the current SQL schema and data model: Before starting the migration, it's important to analyze the current SQL schema
7 min read
SQL queries on FILM Database
Consider the following tables in Film Database: ARTIST (Art_id, Art_Name, Art_Gender) PRODUCER (Prod_id, Prod_Name, Prod_Phone) FILMS (Film_id, Film_Title, Film_Year, Film_Lang, Prod_id) CASTING (Art_id, Film_id, Part) REVIEW (Film_id, Stars) The data content of these five tables are shown below: SELECT * FROM ARTIST;Art_idArt_NameArt_Gender101AMIT
3 min read
Delete Database in MS SQL Server
Prerequisite – Introduction of MS SQL Server and Create Database in MS SQL Server System databases can't be deleted, only user databases could be deleted. Data and log files will automatically be deleted from disk with database deletion. To delete a database, the below methods could be used – SQL Server Management Studio. Transact-SQL. These are ex
1 min read
SQL Query to Set First Day of the Week in a Database
In this article, we are going to write a SQL script to Set the first day of the week in a Database. Below is the implementation for the same. You should have MSSQL in your server. Query in SQL - A query is a request for data or information from a database table or combination of tables. This data can be used for various purposes like Training a mod
2 min read
SQL Query to Add Ranking Positions of Rows in a Database With RANK()
In this article, we will discuss the overview of SQL function RANK and then our main focus will be on Add Ranking Positions of Rows in a Database With RANK() in SQL. Let's discuss it one by one. Overview :Generally, when max/min commands are executed, a single row is displayed as output. RANK() is an SQL function introduced in order to rank the row
2 min read
SQL Query to Add an Agent Parameter in a Database
In this article, we will learn how we add an extra or a new parameter after a table is created using ALTER command in Microsoft SQL Server in detail step-by-step: Step 1: Creating database sales by using the following SQL query: CREATE DATABASE sales; Step 2: Using the database sales by using the following SQL query: USE sales; Step 3: Creating a t
2 min read
SQL Query to Get First and Last Day of a Week in a Database
An SQL query is a single line statement of a Program written in a particular language to perform a specific task. A query consists of some pre-defined functions in SQL like SELECT, CREATE, etc. So, in this article, we will learn about SQL query to get the first and last day of a week in a database. So let's create a database first to do our task, h
2 min read
How to Restore SQL Server Database From Backup?
A Database is defined as a structured form of data that is stored database a computer or data in an organized manner and can be accessed in various ways. It is also the collection of schemas, tables, queries, views, etc. Databases help us with easily storing, accessing, and manipulating data held on a computer. The Database Management System allows
2 min read
Set Database From Single User Mode to Multi User in SQL
A single-user mode specifies that only one user at a time can access the database. If you set the database to single-user mode then all other connections will be closed without warning. If you get disconnected after setting the database into single-user mode, a different user can connect to database, but only one user. Where as in multiple-user mod
4 min read
Microsoft Azure - TDE is Enabled in Azure SQL Database
Pre-requisite: Azure VM Transparent Data EncryptionBy encrypting data at rest, transparent data encryption (TDE) protects Azure SQL Database, Azure SQL Managed Instance, and Azure Synapse Analytics against the threat of unauthorized offline actions. Without requiring changes to the system, it enables real-time encryption and decryption of the datab
3 min read
How to Get Database Size in SQL
SQL database size is vital for effective management. It indicates the storage space occupied by tables, indexes, and other components. Knowing the size of a database is useful for various purposes, such as monitoring the growth, estimating the backup time, planning the storage capacity, and optimizing performance· In this article, we will learn how
6 min read
How to Export Database Schema Without Data in SQL?
Database Schema specifies the structure of a database with its components like tables, columns, and indexes. Exporting data in SQL is an essential task in database management used to perform functions like data backup, recovery, migration, data analysis, performance optimization, compliance, auditing, etc. There may be situations when there is a ne
4 min read
SQL Query to Rename Database
To rename a database in SQL use the ALTER DATABASE Statement with MODIFY NAME clause. The ALTER command in SQL is used to make changes to a table or database. In this article, we will learn how to use the ALTER DATABASE statement with the MODIFY NAME clause to rename a database. How to Rename Database in SQL?To change the name of a database in SQL,
1 min read
How to match username and password in database in SQL ?
In this article, we are going to check the credentials (username and password) entered by the user. If credentials are matched from the database entries, the user can enter into another page and if credentials are incorrect then it displays "Sorry Invalid Username and Password". Pre-requisites: XAMPP server, Basics of HTML, CSS, PHP,  MySQL. Step 1
4 min read
SQL Query to get first and last day of a month in a Database
To get the first and last day of a month in a database, use the DATE_SUB function. It subtracts the day of the month (using the DAYOFMONTH function) minus 1 from the daydate column. This gives us the first day of the month. The LAST_DAY function is used to get the last day of the month for the daydate column. SyntaxThe syntax to get the first and l
2 min read
Check whether a Table exists in SQL Server database or not
Before creating a table, it is always advisable to check whether the table exists in the SQL Server database or not. Checking for table existence before creation helps in avoiding duplication errors, ensures data integrity, and enables efficient database management. There are multiple methods in SQL Server to check if a table already exists in a da
3 min read
SQL Trigger | Student Database
A trigger is a stored procedure in a database that automatically invokes whenever a special event in the database occurs. For example, a trigger can be invoked when a row is inserted into a specified table or when specific table columns are updated. In simple words, a trigger is a collection of SQL statements with particular names that are stored i
7 min read
How to Import and Export SQL Server Database?
Creating and managing a SQL Server database is an essential skill for database administrators and developers. In this article, We will go through the process of setting up a database in SQL Server, from creating the database and tables to inserting records, and finally, exporting and importing the database for backup or transfer purposes. Creating
3 min read
SQL Select Database
The USE DATABASE statement is a command in certain SQL-based database management systems that allows users to select and set a specific database as the default for the current session. By selecting a database, subsequent queries are executed within the context of that database, making it easier to interact with tables and other objects contained wi
3 min read
SQL Server Query to Find All Permissions/Access for All Users in a Database
In SQL databases, managing and auditing user permissions is crucial for ensuring security and proper access control. To find out what permissions or access levels are granted to users within a database, we can use built-in functions such as sys.fn_my_permissions and sys.fn_builtin_permissions. These functions help administrators and database manage
3 min read
SQL DROP DATABASE
SQL DROP DATABASE statement is a powerful command used to permanently delete an existing database from a database management system (DBMS). In this article, We will learn about SQL DROP DATABASE in detail by understanding various examples in detail. SQL DROP DATABASESQL DROP DATABASE statement is used to delete an existing database from the databas
3 min read
Backup Database in MS SQL Server
Creating regular backups of your database is crucial for ensuring data integrity and recovery in case of system failures or accidental data loss. In Microsoft SQL Server, we can create full database backups using either SQL Server Management Studio (SSMS) or Transact-SQL (T-SQL). In this guide, we will learn an overview of the methods for performin
5 min read
Oracle DataBase - Grant Privileges to a User in SQL Command Line
Oracle Database is a robust and widely utilized relational database management system (RDBMS) recognized for its scalability, advanced features and performance optimization. Its architecture supports complex queries and large datasets also making it a popular choice for organizations of all sizes. In this article, We will learn about key factors co
5 min read
Create Database in MariaDB using PyMySQL in Python
MariaDB is an open source Database Management System and its predecessor to MySQL. The pymysql client can be used to interact with MariaDB similar to that of MySQL using Python. In this article we will look into the process of creating a database using pymysql. To create a database use the below syntax: Syntax:CREATE DATABASE databaseName; Example
2 min read
Article Tags :