gpt4 book ai didi

sql - 如何使用 OpenRowSet 将数据插入到空白文件中?

转载 作者:行者123 更新时间:2023-12-01 13:47:38 24 4
gpt4 key购买 nike

使用方法 OpenRowSet 将数据插入空白文件?

我需要从数据库中插入一个 txt 文件(比如 D:\TDB)一些选择输出(比如 select * from sys.tables)

INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Text;Database=D:\TDB;HDR=Yes;', 'SELECT * FROM sys.tables.txt')
select * from sys.tables;

我得到

OLE DB provider "MICROSOFT.JET.OLEDB.4.0" for linked server "(null)" returned message "The Microsoft Jet database engine could not find the object 'sys.tables.txt'. Make sure the object exists and that you spell its name and the path name correctly.".



Msg 7350, Level 16, State 2, Line

1 Cannot get the column information from OLE DB provider "MICROSOFT.JET.OLEDB.4.0" for linked server "(null)".



怎么了?

附注。请不要提出 bcp 解决方案,因为已经测试过并且每次都不起作用,所以我现在要测试 openrowset ..

最佳答案

@serhio ,我在下面测试了你的 sql:

INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Text;Database=D:\TDB;HDR=Yes;', 'SELECT * FROM sys.tables.txt')
select * from sys.tables;

我得到了一些测试结果
  • 文件名不应包含“.”在里面。
    (sys.tables.txt→systables.txt)
  • HDR(Header Row) 不能在这里使用。(删除)
  • txt 文件必须存在。(创建它)
  • txt 文件中的第一行应该是您的所有列名
    源数据。

  • sql
    INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
    'Text;Database=D:\TDB;', 'SELECT * FROM systables.txt')
    select * from sys.tables;

    systables.txt
    name,object_id,principal_id,schema_id,parent_object_id,type,type_desc,create_date,modify_date,is_ms_shipped,is_published,is_schema_published,lob_data_space_id,filestream_data_space_id,max_column_id_used,lock_on_bulk_load,uses_ansi_nulls,is_replicated,has_replication_filter,is_merge_published,is_sync_tran_subscribed,has_unchecked_assembly_data,text_in_row_limit,large_value_types_out_of_row,is_tracked_by_cdc,lock_escalation,lock_escalation_desc

    关于sql - 如何使用 OpenRowSet 将数据插入到空白文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15665311/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com