当源结构和模式结构不相同时,如何将csv数据加载到数据库中?

2024-05-19 02:11:00 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我只为表创建了模式

Student(RollNo,Name,class,Address,EmergencyContactNo)
Course(CourseNo,CourseName)
Student_Course(RollNo,CourseNo)

我有CSV文件,需要加载到相应的表中,由于表的模式和CSV头是相同的,所以在加载数据到学生表和课程表时没有任何问题。但是在Student\u course表中,模式是RollNoCourseNostudent_courseStudentCourse.csv文件的头是StudentNameCourseName。在这种情况下,如何将数据加载到数据库中?有人能解决这个问题吗

-- Schema for StudentCourse Table

Create  table StudentCourse
(
      id int not null IDENTITY(1,1),
      RollNo varchar(50) ,
      CourseNo varchar(40) ,
      primary key(id)
);

StudentCourse.csv

  StudentName,CourseName
  Alwin,CSE
  Brian,CSE
  Cynthia,CSE
  David,CSE
  elizabeth,ECE
  Frank,EEE
  Ganga,ECE
  Hitesh,EEE
  Indra,ECE
  Karthik,ECE

Tags: 文件csv数据模式studentcoursecseece

热门问题