我必须承认,这更像是一个笑话......您应该按照提示使用“导出”并将其写入某种 CSV。纯娱乐:
编辑:创建一个列列表以避免二进制列...
不能直接转换成XML RAW
的列添加了“无效数据”:
DECLARE @Commands TABLE(ID INT IDENTITY,cmd NVARCHAR(MAX));
INSERT INTO @Commands(cmd)
SELECT '(SELECT TOP 3 '
+ STUFF(
(
SELECT ',' + QUOTENAME(COLUMN_NAME)
FROM INFORMATION_SCHEMA.COLUMNS AS c
WHERE c.TABLE_CATALOG=t.TABLE_CATALOG AND c.TABLE_SCHEMA=t.TABLE_SCHEMA AND c.TABLE_NAME=t.TABLE_NAME
AND c.DATA_TYPE NOT IN('image','text') AND c.DATA_TYPE NOT LIKE '%BINARY%'
FOR XML PATH('')
),1,1,''
)
+
(
SELECT ',''invalid data'' AS ' + QUOTENAME(COLUMN_NAME)
FROM INFORMATION_SCHEMA.COLUMNS AS c
WHERE c.TABLE_CATALOG=t.TABLE_CATALOG AND c.TABLE_SCHEMA=t.TABLE_SCHEMA AND c.TABLE_NAME=t.TABLE_NAME
AND (c.DATA_TYPE IN('image','text') OR c.DATA_TYPE LIKE '%BINARY%')
FOR XML PATH('')
)
+ ' FROM ' + QUOTENAME(t.TABLE_CATALOG) + '.' + QUOTENAME(t.TABLE_SCHEMA) + '.'
+ QUOTENAME(t.TABLE_NAME) + ' FOR XML RAW,TYPE) AS ' + QUOTENAME(t.TABLE_CATALOG + '_' + t.TABLE_SCHEMA + '_' + t.TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES AS t WHERE t.TABLE_TYPE='BASE TABLE';
DECLARE @finalCommand NVARCHAR(MAX)=
(
SELECT 'SELECT '
+'(SELECT TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME FROM INFORMATION_SCHEMA.TABLES FOR XML RAW,TYPE) AS ListOfTables'
+ (
SELECT ',' + cmd
FROM @Commands
ORDER BY ID
FOR XML PATH('')
)
+ ' FOR XML PATH(''AllTables'')'
);
EXEC( @finalCommand);