(SQL Tutorials for Citizen Data Scientist)
SQL CREATE DATABASE Statement
In this tutorial you will learn how to create database in a relational database management system like, MySQL, SQL Server, etc. using SQL.
Creating a Database
Before doing anything with the data we must need to create a database first. We’re assuming that you already have a MySQL, or SQL Server available for your use, as well as you’ve all the necessary privileges, if not please check out the getting started guide.
The SQL CREATE DATABASE
statement is used to create a database.
Syntax
The basic syntax for creating a database can be given with:
The following SQL statement creates a database named demo:
Creating a database does not select it for use. So, before moving further we must need to select the target database with the USE
statement. For example, the USE demo;
command sets the demo database as target database for all future commands.
Note: In Unix, the database and table names are case-sensitive, so you must always refer to your database as demo
, not as Demo
, DEMO
, or something else. But, SQL keywords are case-insensitive, like CREATE DATABASE
is same as create database
.
Creating Database in MySQL
Let’s create a database in MySQL using the command-line tool.
Step 1: Invoke the MySQL command-line tool
To invoke the MySQL command line, we’ve to log in to the MySQL server first. To log in as root
user, type the following command in terminal and press enter. You will be asked for your password. Enter your password and press enter, if it is correct the mysql>
prompt will appear, via which you will be able to issue SQL statements and view the results.
Step 2: Creating a MySQL Database
Now, execute the following command to create the database named demo.
If the database created successfully you’ll see the output something like this:
If you try to create a database that is already exists you’ll get an error message. To avoid this in MySQL you can use an optional clause IF NOT EXISTS
as follow:
Step 3: Selecting the Database
Type the following command and press enter. You will see the output “Database changed”. Now our demo database is selected as default database for all future operations.
Beginners Guide to SQL – SQL CREATE DATABASE Statement
Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.
Learn by Coding: v-Tutorials on Applied Machine Learning and Data Science for Beginners
Latest end-to-end Learn by Coding Projects (Jupyter Notebooks) in Python and R:
All Notebooks in One Bundle: Data Science Recipes and Examples in Python & R.
End-to-End Python Machine Learning Recipes & Examples.
End-to-End R Machine Learning Recipes & Examples.
Applied Statistics with R for Beginners and Business Professionals
Data Science and Machine Learning Projects in Python: Tabular Data Analytics
Data Science and Machine Learning Projects in R: Tabular Data Analytics
Python Machine Learning & Data Science Recipes: Learn by Coding
R Machine Learning & Data Science Recipes: Learn by Coding
Comparing Different Machine Learning Algorithms in Python for Classification (FREE)
There are 2000+ End-to-End Python & R Notebooks are available to build Professional Portfolio as a Data Scientist and/or Machine Learning Specialist. All Notebooks are only $29.95. We would like to request you to have a look at the website for FREE the end-to-end notebooks, and then decide whether you would like to purchase or not.