How to Create, Use, and Drop an SQL Database?
A database contains records, and to create, modify, or delete these records SQL queries are used. An SQL query can either be an action query like delete or create or a select query like select or use. These queries are used to find specific data, perform actions on it, or just display data by filtering based on specific criteria.
Check out this comprehensive tutorial video on SQL:
A database is an organized collection of data. How do we create or insert data into the database? Well, that’s done by writing a database query. In this SQL Database tutorial section, we will discuss the queries related to the SQL Database
- How do we Create an SQL Database?
- How do we Use an SQL Database?
- How do we Delete or Drop an SQL Database?
How to Create a Database in SQL?
To Create a Database in SQL
Syntax:
CREATE DATABASE databasename;
where CREATE DATABASE is the keyword and databasename is the name of the database, followed by a semicolon.
Check our guide on DBMS Interview Questions and Answers for better presenting yourself in job interviews.
Here are the steps how to Create a Database in SQL
- Open the SQL software and create a new query by clicking on New Query
- Type the syntax and give a name for your database (Here, we are creating a database ‘happy’)
CREATE DATABASE happy;
- Then hit You will see that your commands are executed successfully, and your table is created.
- Click on Refresh [ ] and you will find a database happy created in Object Explorer
Wish to get certified in SQL! Learn from our SQL expert and do excel in your career with Intellipaat’s SQL certification.
How do we Use an SQL Database?
To Select and use a Database in SQL
Syntax:
USE databasename;
where USE is the keyword, and databasename is the name that we want to use (select it from the existing database names), followed by a semicolon.
Once the database is selected, it remains default until another USE statement with a different database is used. To check which database you’re using, place your mouse pointer over the file where you’re executing the query.
Enroll now in SQL course in Bangalore to learn SQL concepts from experts.
How to Select a Database?
- Here in the above image, the default database is the previously selected as SPARATA
- To select the ‘happy’ database, give the command
USE happy;
- Hit Execute and the database is selected
How do we Delete or Drop an SQL Database?
To delete a database
Syntax:
DROP DATABASE databasename;
where DROP DATABASE is the keyword and databasename is the name of the database we want to delete, followed by semicolon.
Get familiar with the top SQL Interview Questions and Answers to get a head start in your career!
Delete an SQL Database
- Here, we are deleting the igneous database; hence give the following command:
DROP DATABASE igneous;
- Then hit Execute and Click on Refresh [ ], and the igneous database would not be displayed on Object Explorer
This bring us to the end of this SQL Database tutorial part. Now you’re ready to get started with creating and modifying your database! Now you know how to create a database in SQL. Meanwhile, there is a lot more you can do using SQL Database which we will see in the next tutorial sections.