sql序列(1)新建文件夹、建库

1,sql操作文件夹:
-- 允许配置高级选项
exec sp_configure 'show advanced options',1 -- 0|关闭;1|开启
go
-- 重新配置
reconfigure
go
-- 开启xp_cmdshell
exec sp_configure 'xp_cmdshell',1 -- 0|关闭;1|开启
go
-- 重新配置
reconfigure
go
exec xp_cmdshell 'mkdir d:SqlData'
go

exec sys.xp_cmdshell 'mkdir d:sql' --新建文件夹

exec sys.xp_cmdshell 'dir d:sql' --查看文件夹

exec sys.xp_cmdshell 'rd d:sql' --删除文件夹

2,使用t-sql建库

IF EXISTS(SELECT * FROM sysdatabases where name='HotelManagerSystem')
DROP DATABASE HotelManagerSystem
--exec sys.xp_cmdshell 'rd D:SQLDATA'
GO
--创建HotelManagerSystem库
CREATE DATABASE HotelManagerSystem
on primary
(
name='HotelManagerSystem',
filename='D:SQLDATAHotelManagerSystem.mdf',
size=3mb,
maxsize=5mb,
filegrowth=15%
)
log on
(
name='HotelManagerSystem_log',
filename='D:SQLDATAHotelManagerSystem_log.ldf',
size=1mb,
filegrowth=1mb
)
GO

原文地址:https://www.cnblogs.com/namedL/p/9098458.html