<small id='C2EDz'></small><noframes id='C2EDz'>

      <bdo id='C2EDz'></bdo><ul id='C2EDz'></ul>
    <legend id='C2EDz'><style id='C2EDz'><dir id='C2EDz'><q id='C2EDz'></q></dir></style></legend>

        <tfoot id='C2EDz'></tfoot>

        <i id='C2EDz'><tr id='C2EDz'><dt id='C2EDz'><q id='C2EDz'><span id='C2EDz'><b id='C2EDz'><form id='C2EDz'><ins id='C2EDz'></ins><ul id='C2EDz'></ul><sub id='C2EDz'></sub></form><legend id='C2EDz'></legend><bdo id='C2EDz'><pre id='C2EDz'><center id='C2EDz'></center></pre></bdo></b><th id='C2EDz'></th></span></q></dt></tr></i><div id='C2EDz'><tfoot id='C2EDz'></tfoot><dl id='C2EDz'><fieldset id='C2EDz'></fieldset></dl></div>
      1. 使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件

        Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
          <bdo id='xv7tm'></bdo><ul id='xv7tm'></ul>
            <tbody id='xv7tm'></tbody>
          1. <i id='xv7tm'><tr id='xv7tm'><dt id='xv7tm'><q id='xv7tm'><span id='xv7tm'><b id='xv7tm'><form id='xv7tm'><ins id='xv7tm'></ins><ul id='xv7tm'></ul><sub id='xv7tm'></sub></form><legend id='xv7tm'></legend><bdo id='xv7tm'><pre id='xv7tm'><center id='xv7tm'></center></pre></bdo></b><th id='xv7tm'></th></span></q></dt></tr></i><div id='xv7tm'><tfoot id='xv7tm'></tfoot><dl id='xv7tm'><fieldset id='xv7tm'></fieldset></dl></div>
              <legend id='xv7tm'><style id='xv7tm'><dir id='xv7tm'><q id='xv7tm'></q></dir></style></legend>

              • <tfoot id='xv7tm'></tfoot>

                <small id='xv7tm'></small><noframes id='xv7tm'>

                • 本文介绍了使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经看到了许多尝试让 bcp 实用程序将列名与数据一起导出的技巧.如果我所做的只是将表转储到文本文件中,那么让 bcp 添加列标题的最直接方法是什么?

                  I have seen a number of hacks to try to get the bcp utility to export column names along with the data. If all I am doing is dumping a table to a text file what is the most straightforward method to have bcp add the column headers?

                  这是我目前使用的 bcp 命令:

                  Here's the bcp command I am currently using:

                  bcp myschema.dbo.myTableout myTable.csv /SmyServer01 /c /t, -T
                  

                  推荐答案

                  最简单的方法是使用 queryout 选项并使用 union all 将列列表与实际表格内容

                  The easiest is to use the queryout option and use union all to link a column list with the actual table content

                      bcp "select 'col1', 'col2',... union all select * from myschema.dbo.myTableout" queryout myTable.csv /SmyServer01 /c /t, -T
                  

                  示例:

                  create table Question1355876
                  (id int, name varchar(10), someinfo numeric)
                  
                  insert into Question1355876
                  values (1, 'a', 123.12)
                       , (2, 'b', 456.78)
                       , (3, 'c', 901.12)
                       , (4, 'd', 353.76)
                  

                  此查询将返回标题为第一行的信息(注意数值的转换):

                  This query will return the information with the headers as first row (note the casts of the numeric values):

                  select 'col1', 'col2', 'col3'
                  union all
                  select cast(id as varchar(10)), name, cast(someinfo as varchar(28))
                  from Question1355876
                  

                  bcp 命令将是:

                  bcp "select 'col1', 'col2', 'col3' union all select cast(id as varchar(10)), name, cast(someinfo as varchar(28)) from Question1355876" queryout myTable.csv /SmyServer01 /c /t, -T
                  

                  这篇关于使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                  How can I use a single mssql connection pool across several routes in an Express 4 web application?(如何在 Express 4 Web 应用程序中跨多个路由使用单个 mssql 连接池?)
                  • <tfoot id='hJIaU'></tfoot>
                  • <legend id='hJIaU'><style id='hJIaU'><dir id='hJIaU'><q id='hJIaU'></q></dir></style></legend>

                      <bdo id='hJIaU'></bdo><ul id='hJIaU'></ul>
                          <tbody id='hJIaU'></tbody>
                        1. <i id='hJIaU'><tr id='hJIaU'><dt id='hJIaU'><q id='hJIaU'><span id='hJIaU'><b id='hJIaU'><form id='hJIaU'><ins id='hJIaU'></ins><ul id='hJIaU'></ul><sub id='hJIaU'></sub></form><legend id='hJIaU'></legend><bdo id='hJIaU'><pre id='hJIaU'><center id='hJIaU'></center></pre></bdo></b><th id='hJIaU'></th></span></q></dt></tr></i><div id='hJIaU'><tfoot id='hJIaU'></tfoot><dl id='hJIaU'><fieldset id='hJIaU'></fieldset></dl></div>
                          1. <small id='hJIaU'></small><noframes id='hJIaU'>