国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > 建站經(jīng)驗(yàn) > 正文

SQLServer數(shù)據(jù)庫(kù)bcp導(dǎo)出 備份文件應(yīng)用

2019-11-02 15:24:52
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

   /**

  * 授權(quán)

  */

  EXEC sp_configure 'show advanced options',1;

  go

  reconfigure;

  go

  exec sp_configure 'xp_cmdshell',1;

  go

  reconfigure;

  go

  /**導(dǎo)入指定表的文本文件*/

  EXEC master..xp_cmdshell 'bcp dbname..tablename in d:DT.txt -c -Sse

奇米影院[www.aikan.tv/special/miqiyingyuan/]
rvername -Usa -Ppassword'

  exec master..xp_cmdshell 'bcp "select * from dbname..tablename" queryout "D:20140528.xls"-c -Sservername -Uuser -Ppassword'

  xp_cmdshell參數(shù)說(shuō)明

SQLServer數(shù)據(jù)庫(kù)bcp導(dǎo)出備份文件應(yīng)用 電腦高手網(wǎng)

  下面是我自己寫的一個(gè)存儲(chǔ)過(guò)程,可以直接拿去使用

  第一步,先要授權(quán)。上面有授權(quán)的SQL代碼

  if exists(select * from sysobjects where type='p' and name='sp_export_posm_data') begin

  drop procedure sp_export_posm_data;

  end;

  go

  create procedure sp_export_posm_data

  @file_path varchar(200) /*導(dǎo)出后文件存放的路徑*/

  as

  declare @exec_sql varchar(1000);

  declare @file_name varchar(200); /*文件名稱,時(shí)間格式,主要是用于記錄數(shù)據(jù)是什么時(shí)候?qū)С鰝浞莸?/

  declare @table_name varchar(100); /*要導(dǎo)出數(shù)據(jù)的表名*/

  declare @sql varchar(1000); /*執(zhí)行業(yè)務(wù)數(shù)據(jù)查詢的sql語(yǔ)句*/

  /*要備份數(shù)據(jù)的業(yè)務(wù)表名*/

  declare cur_tables cursor for

  select name from sysobjects where 1=1 and type='u'

  and name like 'WM_ORDER%' or name like 'WM_PICKING%' or name like 'RP_%'

  begin try

  open cur_tables;

  fetch next from cur_tables into @table_name;

  while @@FETCH_STATUS = 0 begin

  set @file_name = '';

  set @file_path = '';

  set @sql = 'select * from DHL_POSM_WS..[email protected]_name;

  set @sql += ' where 1=1 and DATEDIFF(MONTH,MODIFY_TIME,GETDATE())>10';

  print @sql;

  set @exec_sql = ' bcp "[email protected]+'" queryout ';

  if [email protected]_path begin

  set @file_path = 'D:Program Files (x86)Microsoft SQL Server';

  end;

  print '111111';

  set @file_name = @table_name+'_'+CONVERT(varchar(100), GETDATE(), 112)+'.xls';

  set @file_path = @file_path + @file_name; /*文件路徑*/

  print '2222222';

  set @exec_sql = @exec_sql +'"[email protected]_path+'"';

  set @exec_sql = @exec_sql +' -c -S"127.0.0.1SQLEXPRESS" -U"DHL_POSM_WS" -P"DHLposm"';

  print @exec_sql;

  -- 導(dǎo)出數(shù)據(jù)到本地文件

  exec master..xp_cmdshell @exec_sql;

  fetch next from cur_tables into @table_name;

  end;

  close cur_tables; -- 關(guān)閉游標(biāo)

  deallocate cur_tables;-- 釋放游標(biāo)

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 江源县| 贵州省| 陵川县| 河南省| 湖北省| 成都市| 北票市| 勐海县| 广西| 教育| 墨脱县| 昭平县| 揭西县| 确山县| 浙江省| 西城区| 原阳县| 郸城县| 格尔木市| 固原市| 团风县| 海南省| 唐山市| 开封县| 浠水县| 井研县| 安塞县| 长顺县| 平舆县| 芜湖县| 上林县| 东乡县| 穆棱市| 宁阳县| 普陀区| 大英县| 东台市| 漠河县| 湾仔区| 故城县| 云林县|