Excel导入数据到sqlserver2005

安装了sqlserver2005后,想从excel导入数据,却找不到“数据导入/出”向导,
相比有不少朋友和我一样无奈,先分享sql语句导入方法如下:

步骤一:启用Ad Hoc Distributed Queries
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

注:如果Ad Hoc Distributed Queries没有启用,会提示“SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问...”

步骤二:执行导入语句
SELECT * INTOtablename FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0',
'Excel 5.0;HDR=YES;DATABASE=C:/test.xls',Sheet1$)

步骤三:关闭Ad Hoc Distributed Queries
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure



你可能感兴趣的:(sqlserver2005)