SQL Server:从 OPENDATASOURCE 中删除

2021-09-10 00:00:00 tsql sql-server

这有效:

SELECT * FROM OPENDATASOURCE( 
       'Microsoft.ACE.OLEDB.12.0', 
       'Data Source=d:\JobFiles\MyFile.xlsx; 
        Extended properties=Excel 8.0')...MySheet$

也是这样:

INSERT INTO OPENDATASOURCE( 
       'Microsoft.ACE.OLEDB.12.0', 
       'Data Source=d:\JobFiles\MyFile.xlsx; 
        Extended properties=Excel 8.0')...MySheet$
SELECT * FROM blahblahblah

那为什么不呢?

DELETE FROM OPENDATASOURCE( 
        'Microsoft.ACE.OLEDB.12.0', 
        'Data Source=d:\JobFiles\MyFile.xlsx;
         Extended properties=Excel 8.0')...MySheet$

我做了一些搜索,但没有真正的运气.归根结底,我需要的只是在插入新数据之前删除 excel 行,我只想使用 SQL 来实现这一点.

I've done some searching with no real luck. At the end of the day, all I need is the excel rows deleted before I can insert fresh data and I want to achieve this with SQL only.

推荐答案

您不能通过 OPENDATASOURCE 删除整行.根据 http://support.microsoft.com/kb/257819:

You cannot delete entire rows via OPENDATASOURCE. According to http://support.microsoft.com/kb/257819:

删除

与删除 Excel 数据相比,您在删除 Excel 数据方面受到更多限制关系数据源.在关系数据库中,行"没有意义或记录"之外的存在;在 Excel 工作表中,这不是真的.您可以删除字段(单元格)中的值.但是,您不能:

You are more restricted in deleting Excel data than data from a relational data source. In a relational database, "row" has no meaning or existence apart from "record"; in an Excel worksheet, this is not true. You can delete values in fields (cells). However, you cannot:

  • 一次删除整个记录,否则您会收到以下错误消息:

此 ISAM 不支持删除链接表中的数据.

您只能通过清空每个记录的内容来删除记录个人领域.

You can only delete a record by blanking out the contents of each individual field.

  • 删除包含 Excel 公式的单元格中的值,否则您会收到以下错误消息:

在这种情况下不允许操作.

  • 您无法删除已删除数据所在的空电子表格行,并且您的记录集将继续显示为空与这些空行对应的记录.

相关文章