简体   繁体   English

如何在sql中填充查询表?

[英]How to populate look up tables in sql?

Hi i am working on look up tables first time and we have some distinct values in look up tables which are coming from excel sheets. 嗨,我是第一次使用查表,我们在查表中有一些与众不同的值,这些值来自excel表。 So i have two databases say A and B. there are around 22 look up tables and 5 certified tables in database A. and one import table and few work table in database B. i am just wondering how i am going to load Look up tables. 所以我有两个数据库,分别是A和B。数据库A中大约有22个查询表和5个经过认证的表。数据库B中有一个导入表和几个工作表。我只是想知道如何加载查询表。 do i have to write stored procs for each look up table and use in SSIS package. 我是否必须为每个查找表编写存储的proc并在SSIS包中使用。 i just have to get distinct values from the Excel sheet for respective look up tables. 我只需要从Excel工作表中为各个查找表获取不同的值即可。 i am using SQL Server 2005. Thanks for reading this. 我正在使用SQL Server2005。感谢您阅读本文。

1) Save the excel sheet as csv (use "Save As" from file menu) 1)将Excel工作表另存为csv(使用文件菜单中的“另存为”)

2) Set "IGNORE_DUP_KEY" option on the destination table, this will skip duplicate values in CSV files(excel sheet) 2)在目标表上设置“ IGNORE_DUP_KEY”选项,这将跳过CSV文件(Excel工作表)中的重复值

3) construct a BULK INSERT command and provide the csv file and the destination table. 3)构造一个BULK INSERT命令,并提供csv文件和目标表。

Alternative to 2) You may also set MAXERRORS in the BULK INSERT command to a value higher than the number of lines in csv file, this options just ignores any errors(there fore all the duplicate key errors will not cause the INSERT to fail) 替代2)您也可以在BULK INSERT命令中将MAXERRORS设置为高于csv文件中的行数的值,此选项仅忽略任何错误(因此所有重复的键错误都不会导致INSERT失败)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM