Microsoft SQL Server/Database manipulation
外观
创建数据库
[编辑]创建的每个数据库都会创建相应的文件:
- Master Database File (.mdf)
- Log Database File (.ldf)
CREATE DATABASE [MyDB] ON PRIMARY
( NAME = N'MyDB', FILENAME = N'D:\DATASQL\MSSQL10.MSSQLSERVER\MSSQL\DATA\MyDB.mdf' , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'MyDB_log', FILENAME = N'D:\DATASQL\MSSQL10.MSSQLSERVER\MSSQL\DATA\MyDB_log.ldf' , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
读取
[编辑]显式指明数据库:
USE MyDB;
SELECT * FROM MyTable;
或使用全路径:
SELECT * FROM [MyDB].[dbo].[MyTable];
备份
[编辑]恢复
[编辑]RESTORE DATABASE MyDB
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\Backup\2016-02-16-MyDB.bak'
WITH REPLACE