English 中文(简体)
MS SQL Server - Create Database
  • 时间:2024-11-03

MS SQL Server - Create Database


Previous Page Next Page  

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

System databases are created automatically when we install MS SQL Server. Following is a pst of system databases −

    Master

    Model

    MSDB

    Tempdb

    Resource (Introduced in 2005 version)

    Distribution (It’s for Reppcation feature only)

User Databases

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>

OR

Restore Database <Your database name> from disk =  <Backup file location &plus; file name>

Example

To create database called ‘Testdb’, run the following query.

Create database Testdb

OR

Restore database Testdb from disk =  D:BackupTestdb_full_backup.bak 

Note − D:ackup 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-cpck on the databases folder. Cpck on new database and the following screen will appear.

New Database

Enter the database name field with your database name (example: to create database with the name ‘Testdb’) and cpck OK. Testdb database will be created as shown in the following snapshot.

Create Database Advertisements