[SQL Server] Excel文件导入SQL Server数据库表

  
    
/*
OFFICE 2003
如果接受数据导入的表已经存在:
*/
INSERT INTO DemoTable
SELECT *
FROM OPENROWSET
(
' MICROSOFT.JET.OLEDB.4.0 '
,
' Excel 5.0;HDR=YES;DATABASE=D:\Demo.xls '
,sheet1$
)
/*
如果导入数据并生成表:
*/
SELECT * INTO DemoTable
FROM OPENROWSET
(
' MICROSOFT.JET.OLEDB.4.0 '
,
' Excel 5.0;HDR=YES;DATABASE=D:\Demo.xls '
,sheet1$
)

/* =================================== */

/*
OFFICE 2010
如果表已存在,SQL语句为:
*/
INSERT INTO DemoTable
SELECT *
FROM OPENDATASOURCE
(
' Microsoft.Ace.OLEDB.12.0 '
,
' Data Source=D:\Demo.xlsx;Extended Properties=Excel 12.0 '
)
...
[ sheet1$ ]

/*
如果表不存在,SQL语句为:
*/
SELECT * INTO DemoTable
FROM OPENDATASOURCE
(
' Microsoft.Ace.OLEDB.12.0 '
,
' Data Source=D:\Demo.xlsx;Extended Properties=Excel 12.0 '
)...
[ sheet1$ ]

转载至:http://www.cnblogs.com/txst/archive/2011/04/21/2023372.html

 

 

你可能感兴趣的:(SQL Server)