您的位置:首页 > 数据库

使用SQL 脚本 导入 Excel 数据

2011-11-23 21:19 316 查看
一、导入到 Mysql 数据库 先将excel 文件另存为 *.csv 文件,然后执行下列命令。

load data local infile "path.csv" into talble(col1,col2,col3,col4,...);

二、导入Sql Server 数据库

首先需要开户 Ad Hoc Distributed Queries 选项,开户方法如下:

exec sp_configure 'show advanced options',1 reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

然后执行:

SELECT * into newtable
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0', 'Data Source="F:\一页管理.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$]

最后关闭 Ad Hoc Distributed Queries 选项

exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0reconfigure
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: