1.创建数据库
假设SQL Server服务已启动,并以Administrator身份登录计算机(文件名称自定);请分别使用Management界面方式和T-SQL语句实现以下操作:
CREATE DATABASE student ON (NAME = stu, FILENAME = ‘D:\stu_data.mdf’, SIZE = 3MB, MAXSIZE = 500MB, FILEGROWTH = 10%) LOG ON (NAME = stu_log, FILENAME = ‘D:\stu_log.ldf’, SIZE = 3MB, MAXSIZE = unlimited, FILEGROWTH = 1MB)
CREATE DATABASE Company ON (NAME = Company_data, FILENAME = ‘C:\Company.mdf’, SIZE = 10MB, MAXSIZE = unlimited, FILEGROWTH = 10%) LOG ON (NAME = Company_log, FILENAME = ‘C:\Company.ldf’, SIZE = 1MB, MAXSIZE = 50MB, FILEGROWTH = 1MB)
CREATE DATABASE DB ON (NAME = DB_data1, FILENAME = ‘D:\ceshi\DB_data1.mdf’, SIZE = 5MB, MAXSIZE = 100MB, FILEGROWTH = 10%), (NAME = DB_data2, FILENAME = ‘D:\ceshi\DB_data2.mdf’, SIZE = 5MB, MAXSIZE = 100MB, FILEGROWTH = 10%) LOG ON (NAME = Company_log, FILENAME = ‘D:\ceshi\DB_log.ldf’, SIZE = 3MB, MAXSIZE = unlimited, FILEGROWTH = 10%)
2.修改数据库
ALTER DATABASE student ADD FILE ( NAME = db2, SIZE = 10MB, MAXSIZE = 50MB, FILENAME = ‘D:\db2.mdf’, FILEGROWTH = 10%)
ALTER DATABASE student ADD LOG FILE ( NAME = df, SIZE = 1MB, MAXSIZE = unlimited, FILEGROWTH = 1MB, FILENAME = ‘D:\df.ldf’)
ALTER DATABASE student MODIFY FILE ( NAME = stu, SIZE = 10MB, FILEGROWTH = 20%)
3.删除数据库
ALTER DATABASE student remove FILE db2 go ALTER DATABASE student remove FILE df
DROP DATABASE Company
4.创建及删除模式(构架)
CREATE SCHEMA stu AUTHORIZATION dbo
CREATE SCHEMA AUTHORIZATION test
DROP SCHEMA stu
如何将数据库student的所有物理文件移动到‘D:\xxx‘,并且保证逻辑数据库不受影响,请详细描述解决办法。
先分离数据库,然后移动数据库文件,最后再附加进去。