Exporting all tables into files from SQL Server database using utility bulk copy
问题 I want to bcp all tables into files from a database: SELECT 'EXEC xp_cmdshell ''bcp ' --bcp + QUOTENAME(DB_NAME())+ '.' --database name + QUOTENAME(SCHEMA_NAME(SCHEMA_ID))+ '.' -- schema + QUOTENAME(name) -- table + ' out c:\temp\' -- output directory + REPLACE(SCHEMA_NAME(schema_id),' ','') + '_' + REPLACE(name,' ','') -- file name + '.txt -T -c''' -- extension, security FROM sys.tables it produces statements like this: EXEC xp_cmdshell 'bcp [AdventureWorks2012].[Production].[ScrapReason]