SQL Server Database_ Create, Alter, & Drop Database in SQL
SQL Server Database_ Create, Alter, & Drop Database in SQL
Comarch
hcramo What is Database?
ramoC
Get Your Free
A Database is a collection of objects such as tables, views, stored
procedures, triggers, functions, etc.
Similarly, we have DATABASE which is a kind of home for all our tables, views, stored procedures, etc which are
interlinked.
Technically, Database store the data in a well-organized manner for easy access and retrieval. In SQL Server,
there are two types of databases:
1. System Databases: The system databases are created automatically for you when you install the SQL Server.
They play a crucial role in the server, especially in ensuring that database objects run correctly. Examples of
SQL Server system databases include: Master, MSDB, Model, Tempdb, Resource
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 1/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
2. User Databases: The user databases are created by the database users like you who have been granted
access to create databases
Table of Content:
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 2/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 3/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
Step 1) Right Click on ‘Database’ from ‘Object Explorer’ window and then select ‘New Database.’
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 4/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
Step 2) Below ‘New Database’ screen will appear. Enter ‘Database name’.Note that: ‘Logical name’ column will
be auto-populated with:
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 5/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
Here:
A) Edu | Filetypes: Rows and Filegroups: PRIMARY is .mdf file
Step 3) (Optional) For more Complex settings, we can navigate to ‘Options’ and ‘Filegroups’.At Beginner level,
creating Database from General Tab will suffice.
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 6/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 7/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
We can expand Database – ‘Edu’ which will contain Tables, View, etc. These are initially blank until the user
creates new Table, views, etc.
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 8/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 9/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
Query Window:
Create Script:
USE [master]
GO
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'Edu', FILENAME = N'C:\Program Files\Microsoft SQL
Server\MSSQL14.SQL_MS\MSSQL\DATA\Edu.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH =
65536KB )
LOG ON
( NAME = N'Edu_log', FILENAME = N'C:\Program Files\Microsoft SQL
Server\MSSQL14.SQL_MS\MSSQL\DATA\Edu_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH =
65536KB )
Syntax:
Query:
Click on ‘Execute’
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 11/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 12/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
RELATED ARTICLES
→ SSRS Tutorial: What is SQL Server Reporting Services?
→ SQL Variables: SQL Server Declare, Set and Select Variable
→ Substring() in SQL Server: How to use Function with Example
→ Top 40 SSIS Interview Questions and Answers (2024)
Let’s have a look when we want to Create Database with .mdf and .ldf file. Here, we can give the location as an
implicit part of our query.
Syntax:
Query:
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 13/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
ON PRIMARY
( NAME = N'Edu_TSQL_file', FILENAME = N'C:\Program Files\Microsoft SQL
Server\MSSQL14.SQL_MS\MSSQL\DATA\Edu_TSQL_file.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED,
FILEGROWTH = 65536KB )
LOG ON
( NAME = N'Edu_TSQL_file_log', FILENAME = N'C:\Program Files\Microsoft SQL
Server\MSSQL14.SQL_MS\MSSQL\DATA\Edu_TSQL_file_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB ,
FILEGROWTH = 65536KB )
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 15/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
Syntax:
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 17/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
Query:
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 18/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
General Syntax:
Query:
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 20/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
Delete Database
There are 2 ways to Delete Database in SQL server.
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 22/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
Syntax:
Query:
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 23/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
USE master;
GO
DROP DATABASE Edu_TSQL_Alter;
GO
You can create a database by restoring a database you had backed up earlier. It can be done by running the
restore database command which takes the following syntax:
restore Database <database name> from disk = '<Backup file location + filename>
The query should be executed within the query window just like out previous command. For example:
You can also use the GUI Navigation: Right Click Database>Restore Databases>Device> Import file>Click Ok.
Summary
We can use both SQL Management GUI and T-SQL to perform all the three operations; Create, Alter and
Delete Database.
A maximum of 32,767 databases can be specified on an instance of SQL Server.
System Databases cannot be deleted.
Create, Alter & Drop: All operations are case insensitive. We can use both upper and lower case as a syntax.
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 25/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
SQL
SQL Server What is SQL
Architecture Server?
(Explained)
(Explained) Introduction,…
SQL Server
Server Top 50 SQL Server
CREATE, ALTER, Interview
DROP
DROP Table… Questions…
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 26/28
12/6/24, 6:32 PM SQL Server Database: Create, Alter, & Drop Database in SQL
Do you think
AI is future of
Work?
Yes No
Top Tutorials
About
About Us
Advertise with Us
Contact Us
Career Suggestion
SAP Career Suggestion
Tool
Software Testing as a
Career
Xero
RemotePC SAP Java SQL
QuickBooks
Interesting
eBook
Blog
Quiz
SAP eBook
Privacy Manager
Selenium Build Website VPNs
https://www.guru99.com/sql-server-database-create-alter-drop-restore.html 28/28