sql2005数据导入导出

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO

EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1
RECONFIGURE
GO

--从sql server中导出数据到excel
--exec master..xp_cmdshell 'bcp TestB.dbo.t_course out d:\Sheet1.xls -c -q -S"Z00200534" -U"sa" -P"Snail807@hw"'

--从excel导入sql server表
select *
from OpenDataSource('Micro.Jet.OLEDB.4.0',
'Data Source="D:\Sheet2.xls";User ID=sa;Password=Snail807@hw;HDR=NO;Extend properties=Excel 8.0')...[Sheet1$]

-- 导入Excel中指定的列到数据库表中指定的列
--insert into DBtableName(t_c_courseno, t_c_name, t_c_score) select t_c_courseno, t_c_name, t_c_score
--from OpenDataSource('Microsoft.Jet.OLEDB.4.0', 'Data Source="d:\temp1.xls";User ID=sa;Password=Snail807@hw;Extended properties=Excel 8.0')...[sheet1$]

-- 导入数据并生成表
--SELECT *  into DBtableName  FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;HDR=YES;Data Source="d:\Sheet1.xls;User ID=sa;Password=Snail807@hw;Extended properties="Excel 8.0"', [Sheet1$])

--查询
--SELECT * FROM OPENROWSET( 'MICROSOFT.JET.OLEDB.4.0','Excel8.0;IMEX=1;HDR=NO;Date Source=D:\Sheet1.xls',[sheet1$])

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