且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将excel中的实时数据导入sql server数据库

更新时间:2023-01-21 16:27:02

可能存在一个不太复杂的解决方案。但不是没有一些关于Excel的主题阅读...



然而,您可以将您的电子表格保存为带有.txt扩展名的文本文件,确保它'std(制表符分隔)。这样的结果将导致:

Likely a less complicated solution exists. But not without some reading up on the subject wrt Excel ...

You could however just "save" your spreadsheet as a text file with .txt extention making sure it''s "td" (tab-delimited). Something like this will result:
001	Stars&StripesForever	sousa@phoneydata.com	yes	2005-05-02 11:59:00.001
002	AintNoWomanLiketheOneIGot	peaches@twentysixteen.com	yes	2005-12-14 11:59:02.110
003	100101011100111100000011	ss@nautpott.com	no	2013-02-07 07:77:59.077 



In SQL2005 Studio Management应用程序,点击创建新查询按钮创建一个新的.sql查询



复制此代码:


In SQL2005 Studio Management application, create a new .sql "query" by clicking on "Create New Query" button

Copy this code:

USE [cpqaAnswer]
GO

CREATE SCHEMA [cpqa]

CREATE TABLE [cpqaAnswer].[cpqa].[tblExcelTdData](
 [idx][int],
    [title][nvarchar](128),
       [email][nvarchar](256)
          [status][nvarchar](16),
             [time][datetime]
             )

BULK INSERT [cpqaAnswer].[cpqa].[tblExcelTdDate] FROM ''C:\users\pn\datafile(td).txt''



将其粘贴到编辑器中,然后键入新的SELECT子句以查看表格数据:


Paste it in the editor, then type in a new SELECT clause to see the tabled data:

SELECT * FROM [cpqaAnswer].[cpqa].[tblExcelTdData]