- MS SQL Server
- MS SQL Server - Home
- MS SQL Server - Overview
- MS SQL Server – Editions
- MS SQL Server – Installation
- MS SQL Server – Architecture
- MS SQL Server – Managment Studio
- MS SQL Server – Login Database
- MS SQL Server - Create Database
- MS SQL Server - Select Database
- MS SQL Server - Drop Database
- MS SQL Server - Creating Backups
- MS SQL Server - Restoring Databases
- MS SQL Server - Create Users
- MS SQL Server - Assign Permissions
- MS SQL Server - Monitor Database
- MS SQL Server - Services
- MS SQL Server - HA Technologies
- MS SQL Server - Reporting services
- MS SQL Server - Execution Plans
- MS SQL Server - Integration Services
- MS SQL Server - Analysis Services
- MS SQL Server Useful Resources
- MS SQL Server - Quick Guide
- MS SQL Server - Useful Resources
- MS SQL Server - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MS SQL Server - Create Database
Database is a collection of objects such as table, view, stored procedure, function, trigger, etc.
In MS SQL Server, two types of databases are available.
- System databases
- User Databases
System databases are created automatically when we install MS SQL Server. Following is a list of system databases −
- Resource (Introduced in 2005 version)
- Distribution (It’s for Replication feature only)
User databases are created by users (Administrators, developers, and testers who have access to create databases).
Following methods are used to create user database.
Method 1 – Using T-SQL Script or Restore Database
Following is the basic syntax for creating database in MS SQL Server.
Create database <yourdatabasename>
Restore Database <Your database name> from disk = '<Backup file location + file name>
To create database called ‘Testdb’, run the following query.
Create database Testdb
Restore database Testdb from disk = 'D:\Backup\Testdb_full_backup.bak'
Note − D:\backup is location of backup file and Testdb_full_backup.bak is the backup file name
Method 2 – Using SQL Server Management Studio
Connect to SQL Server instance and right-click on the databases folder. Click on new database and the following screen will appear.
Enter the database name field with your database name (example: to create database with the name ‘Testdb’) and click OK. Testdb database will be created as shown in the following snapshot.