LogIn
I don't have account.

CREATE Database in SQL

DevSniper
108 Views

A database is an organized collection of data stored in a computer system, designed to facilitate efficient data storage and retrieval. Different query languages can be used to create and manage databases and SQL is one such language. Creating a database in SQL is one of the first steps in setting up a structured environment to store and manage data efficiently. After creating a database you can start creating tables, views, stored procedures and other database objects within it.

CREATE DATABASE Statement

CREATE DATABASE statement is a Data Definition Language (DDL) command in SQL which is used to create a new database.

Syntax

CREATE DATABASE DatabaseName;

Example :-

If you plan to create a database to store user data in this case your database name would be Users and your database create command will be

CREATE DATABASE Users;

If Database already exist

If the database name already exists, you will get an error. To avoid this, you should use the IF NOT EXISTS

CREATE DATABASE IF NOT EXISTS DatabaseName

If you plan to create a database to store user data, the database name should be Users and your command to create database would be

CREATE DATABASE IF NOT EXISTS Users;

Verifying Database Creation

If you want to check is database present or not. you would run below command

SHOW DATABASE;

Key Characteristics

  • To create a database, you need to have admin privileges.
  • It's important to note that on Linux or Unix systems, database names are case-sensitive, while SQL keywords are not. However, on Windows systems, this case-sensitivity does not apply.
  • If you don't have the necessary privileges, you may encounter a "permission denied" error.
  • The name of your database should be clear and descriptive of its content.
  • Make sure to assign the appropriate permissions to users. You may need to provide users specific privileges such as SELECT, INSERT or UPDATE, while restricting others from dropping or altering the database.
  • Make sure to implement a regular backup strategy for your database. It is important to prevent data loss in case of unexpected issues.