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

ExpandedBlockStart.gif 代码
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. 

ExpandedBlockStart.gif 代码
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


 

posted on 2010-07-27 15:15 搏击的小船 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/guanjie20/archive/2010/07/27/1786033.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值