【问题标题】:Load raw data to SQL Server将原始数据加载到 SQL Server
【发布时间】:2021-10-06 14:04:19
【问题描述】:

在 csv 文件中提供了学生表的数据。 DDL 创建表:


Create Table students 
(
    Student_Name nvarchar(50),
    S1 int,
    S2 int,
    S3 int
);

文件中的样本数据:

Student_Name,S1,S2,S3
John Doe,92,90,98
John,88,78,54

为了加载这个,我为整个文件构建了一个 insert into values 代码块,看起来像这样:

insert into Students values
('John Doe',92,90,98),
('John',88,78,549)

我尝试的另一种方法是 SQL 服务器导入任务,所有数据都以字符串格式结尾。必须再次将数据转换/转换为 int 格式的 S1,S2 and S3 列。

除了这些之外,还有其他方法可以以最简单的方式加载数据吗?

【问题讨论】:

标签: sql-server sql-server-2019


【解决方案1】:

您可以使用 select * into Newtable 或 InsertInto ExistingTable from Datatable。 例如

SELECT c.FirstName, c.LastName, e.JobTitle, a.AddressLine1, a.City,   
    sp.Name AS [State/Province], a.PostalCode  
INTO dbo.EmployeeAddresses  
FROM Person.Person AS c  
    JOIN HumanResources.Employee AS e   
    ON e.BusinessEntityID = c.BusinessEntityID  
    JOIN Person.BusinessEntityAddress AS bea  
    ON e.BusinessEntityID = bea.BusinessEntityID  
    JOIN Person.Address AS a  
    ON bea.AddressID = a.AddressID  
    JOIN Person.StateProvince as sp   
    ON sp.StateProvinceID = a.StateProvinceID;  
GO  

【讨论】:

  • 这个答案与这个问题没有任何关系。
猜你喜欢
  • 1970-01-01
  • 2010-12-17
  • 1970-01-01
  • 2019-01-06
  • 2023-04-04
  • 1970-01-01
  • 2016-05-15
  • 1970-01-01
  • 2016-11-01
相关资源
最近更新 更多