sql语句创建文件夹、判断文件夹、创建数据库、表、

代码
USE master;
GO
if  exists (select * from sys.databases where name = 'TestDB')
drop database TestDB

--创建文件夹
EXEC sp_configure 'show advanced options'1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell'1
RECONFIGURE
GO
ExEc xp_cmdshell 'mkdir D:\aaa' --调用DOS命令创建project文件夹 
--
exec xp_cmdshell 'rd d:\new /s/q' --删除文件夹 
--
创建数据库
/*
*
注意:
1,FILENAME路径;
2,初始化数据库大小和增长方式
*
*/
EXECUTE ('CREATE DATABASE TestDB
ON 
( NAME = TestDB_dat,
    FILENAME = 
''D:\aaa\TestDB.mdf'',
    SIZE = 500,
    MAXSIZE = UNLIMITED,
    FILEGROWTH = 100 )
LOG ON
( NAME = TestDB_log,
    FILENAME = 
''D:\aaa\TestDB.ldf'',
    SIZE = 500,
    MAXSIZE = UNLIMITED,
    FILEGROWTH = 100 )
'
);


下面是一段判断文件夹是否存在的SQL语句

xp_fileexist: Checks to see if a given file exists or not. It returns three columns with a value of 1 (yes) or 0 (no): File Exists, File is a Directory and Parent Directory Exists. 

代码
CREATE TABLE #tmp ([File Exists] BIT[File is a Directory] BIT[Parent Directory Exists] BIT)
 
 
INSERT INTO #tmp ([File Exists][File is a Directory][Parent Directory Exists])
 
 
EXEC master.dbo.xp_fileexist 'D:\aaa'
 
 
SELECT * FROM #tmp
 
 
DROP TABLE #tmp


原文地址:https://www.cnblogs.com/guanjie20/p/1786033.html