我需要通过电子表格(唯一可用的选项)每天更新SQL 2008数据库。这种格式非常基本,但是可能有数百万条记录。 Column1和Column3将具有许多预定义的重复值,已经拉出到单独的表中。
电子表格样品
Column1 Column2 Column3
Apple 10 Red
Apple 20 Red
Apple 15 Blue
Apple 21 Green
Orange 10 Orange
Orange 7 Orange
Orange 9 Red
Orange 70 Blue
Orange 10 Blue
DB设置
我的数据库设置了三个独立的表:
//Lookup_Column1
id type
1 Apple
2 Orange
//Lookup_Column3
id type
1 Red
2 Blue
3 Green
4 Orange
//Main - this is what should be inserted, after Column1
//and Column2 are matched to their respective ID's
key Column1 Column2 Column3
1 1 10 1
2 1 20 1
3 1 15 2
4 1 21 3
5 2 10 4
6 2 7 4
7 2 9 1
8 2 70 2
9 2 10 2
问题
如何编写SQL以插入与查找表中的信息匹配的记录?我怎样才能从这个去:
INSERT INTO Main(Column1, Column2) VALUES ('Apple', 10, 'Red');
要这样:
INSERT INTO Main(Column1, Column2) VALUES (1, 10, 1);
//pulled from lookup tables, where Apple = 1 and Red = 1
您打算如何将电子表格数据导入sql-server? –