Ms Sql Server 简明教程
MS SQL Server - Create Database
数据库是表格、视图、储存过程、函数、触发器等对象的集合。
Database is a collection of objects such as table, view, stored procedure, function, trigger, etc.
在 MS SQL Server 中,可用两种类型的数据库。
In MS SQL Server, two types of databases are available.
-
System databases
-
User Databases
System Databases
系统数据库在安装 MS SQL Server 时自动创建。下面是系统数据库列表 -
System databases are created automatically when we install MS SQL Server. Following is a list of system databases −
-
Master
-
Model
-
MSDB
-
Tempdb
-
Resource (Introduced in 2005 version)
-
Distribution (It’s for Replication 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
以下是用于在 MS SQL Server 中创建数据库的基本语法。
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 + file name>
Example
要创建名为“Testdb”的数据库,请运行以下查询。
To create database called ‘Testdb’, run the following query.
Create database Testdb
或
OR
Restore database Testdb from disk = 'D:\Backup\Testdb_full_backup.bak'
Note - 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
连接到 SQL Server 实例并右键单击数据库文件夹。单击新建数据库,将出现以下屏幕。
Connect to SQL Server instance and right-click on the databases folder. Click on new database and the following screen will appear.
在数据库名称字段中输入数据库名称(示例:要使用名称“Testdb”创建数据库),然后单击确定。Testdb 数据库将创建,如下面的截图所示。
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.