A database includes records, and SQL queries are used to construct, alter, or remove those records. An SQL query may be either a delete or build action query, or a select query such as pick or use. Such queries are used for searching based on particular parameters to locate specific data , perform actions on it, or simply to show the data.
A database is an organized data-gathering. Where are we going to build or insert data into database? Well, that is done by writing a query about a database. In this section of the SQL Database tutorial, we’ll discuss the SQL Database queries
How to Create a Database in SQL?
To Create a Database in SQL
CREATE DATABASE databasename;
where CREATE DATABASE is the keyword and databasename is the name of the database, followed by a semicolon.
Here are the steps to build a SQL Database
- Click on New Query to open the SQL software and create a new query
- Type the syntax and give your database a name (Here we are building a ‘happy’ database)
CREATE DATABASE happy;
- Then hit You’ll see your commands are successfully executed, and your table is created.
- Click Refresh to find a Happy Database created in Object Explorer
How do we Use a SQL Database?
To Select and use a Database in SQL
Where USE is the keyword and the name of the database we want to use (select it from the existing database names) followed by a semicolon.
Once you have selected the database, it remains default until you use another USE statement with a different database. To verify which database you are using, place your mouse pointer over the file where the query is being executed.
How to Choose a Database?
- The default database here in the above image is the one previously selected as SPARATA
- Fill in the order to find the ‘happy’ folder
- Click Execute, and pick the database
How do we Delete or Drop a SQL Database?
To delete a database
DROP DATABASE databasename;
Where DROP DATABASE is the keyword and the name of the database that we want to delete preceded by a semicolon.
Here, the igneous database is deleted; therefore we give the following command:
DROP DATABASE igneous;
- Then hit Run and Click Refresh and the igneous database will not appear on Object Explorer
This will push us to the end of this tutorial portion of the SQL Server. Now you’re able to start building and amending your database! Now you know how to make a SQL database. Meanwhile, there’s a lot more you can do using SQL Database that we’ll see in the next parts of tutorial.