MSSQL is good database.   Unlike as Oracle,  it seems that can not backup sqlserver databasee tables one by one.

 

However there is always way.

 

Thanks to

How to backup on MSSQL by table level ?

I  did modify and then , it can auto baclkup table one by one no matter how many table is.

How to backup on MSSQL by table level ?

 

Here is script:

 

-- SQL Table Backup

-- Developed by DBATAG, www.DBATAG.com

DECLARE @table VARCHAR(128),

@file VARCHAR(255),

@cmd VARCHAR(512)

 

declare @m int

declare @n int

--declare @tmp nvarchar(MAX)

 

declare  @tableList TABLE (id int IDENTITY(1,1) NOT NULL,contents VARCHAR(128) NOT NULL)

DECLARE @SQL2 VARCHAR(MAX)

 

SET NOCOUNT ON

set @SQL2='select DB_NAME()+''.'' +schema_name() + ''.''+ name from sys.tables where type=''U'''

 

INSERT INTO @tableList (contents) exec (@SQL2)

 

set @m=(select count(*) from @tableList)

set @n=1

 

while @n<[email protected]

begin

set @table=(select contents from @tableList where [email protected])

 

--SET @table = 'AdventureWorks.Person.Contact' --  Table Name which you want    to backup

--SET @table = 'MES.dbo.Sys_Group'

--SET @table = 'select name from sys.tables where type='U' order by 1'

SET @file = 'C:\backup\' + @table + '_' + CONVERT(CHAR(8), GETDATE(), 112) --  Replace C:\MSSQL\Backup\ to destination dir where you want to place table data backup

+ '.bcp'

SET @cmd = 'bcp ' + @table + ' out ' + @file + ' -n -T '

EXEC master..xp_cmdshell @cmd

set @[email protected]+1

end

 

 

Bingo

相关文章:

  • 2021-08-15
  • 2021-06-06
  • 2022-12-23
  • 2022-01-09
  • 2021-06-28
  • 2022-02-20
  • 2021-07-05
  • 2021-11-15
猜你喜欢
  • 2022-01-03
  • 2021-06-01
  • 2021-12-14
  • 2022-01-16
  • 2021-10-01
  • 2022-12-23
相关资源
相似解决方案