There are no items in your cart
Add More
Add More
Item Details | Price |
---|
Wed Apr 3, 2024
For creating a database there are two ways:
We will create database using both method.
You can use the below syntax for creating a database.
CREATE DATABASE DataBase_Name;
Let’s create a database named “Demo_DB”.
Syntax:
CREATE DATABASE Demo_DB;
Creating database Using SQL Server Management Studio (Manually):
First, right-click on the “Databases” folder in the Object Explorer pane, and select “New Database…”
Now, in the “New Database” dialog box, specify the name for your new database in the “Database name” field.
Click on the “Options” tab to specify additional settings for the database, such as recovery model, backup options, and compatibility level.
At the end, Click “OK” to create the new database.
After creating a database in SQL Server, you can view it in SQL Server Management Studio by expanding the “Databases” folder. The new database should appear in the list of databases. As you can see in the below image:Alternatively, you can use the following T-SQL command to view a list of all databases on the server:
SELECT name FROM sys.databases;
Result:
Above query will display a list of all databases on the server, including the one you just created.
You can also filter the results by using a WHERE clause to search for a specific database name, by using the following syntax.
SELECT name FROM sys.databases WHERE name = ‘Demo_DB’;
How to use a database?
There are two ways to use a database:
USE database_name; We have created a database, named “Demo_DB”. Let’s use this database using SQL Statement-
USE Demo_DB;
2.Manually from SQL Server Management Studio –
We can manually choose the database which we want to use. As shown in below image:Delete/ Drop a database:
To drop a database in SQL Server, you can use the following query:
DROP DATABASE Demo_DB;
Note: Be very careful when dropping a database, as it will permanently delete all data and cannot be undone. Before dropping a database, it is important to keep the following things in mind:
Vijay Kashyap
Discover SQL in a straightforward and uncomplicated manner.