简体   繁体   English

SQL Server高性能插入两个相关表

[英]Sql Server high performance insert in two related tables

Sirs, 先生们

I have the following physical model below, resembling an class table inheritance like the pattern from Fowler ( http://martinfowler.com/eaaCatalog/classTableInheritance.html ) 我在下面有以下物理模型,类似于类表继承,如Fowler的模式( http://martinfowler.com/eaaCatalog/classTableInheritance.html

CREATE TABLE [dbo].[ProductItem] (
[IdProductItem]     INT             IDENTITY (1, 1) NOT NULL,
[IdPointOfSale]     INT             NOT NULL,
[IdDiscountRules]   INT             NOT NULL,
[IdProductPrice]    INT             NULL);

CREATE TABLE [dbo].[Cellphone] (
[IdCellphone]    INT          IDENTITY (1, 1) NOT NULL,
[IdModel]    INT          NOT NULL,
[IMEI]  NVARCHAR (150) NOT NULL,
[IdProductItem] INT  NULL
);

ProductItem is my base class. ProductItem是我的基类。 It handles all actions related to the sales. 它处理与销售有关的所有动作。 Cellphone is a subclass from ProductItem. 手机是ProductItem的子类。 It adds the atributes and behavior specific that I need to use when I sell an cellphone (IMEI number, activate the cell phone etc) 它增加了我在出售手机时需要使用的属性和行为(IMEI号码,激活手机等)

I need to track each item of the inventory individually. 我需要单独跟踪库存的每个项目。 When I receive a batch of 10.000 cellphone, I need to load all this information in my system. 当我收到一批10.000手机时,我需要在系统中加载所有这些信息。 I need to create the cellphones and the productitem in my database. 我需要在数据库中创建手机和产品。

If it was only one table, it is easy to use bulk insert. 如果只有一张桌子,则很容易使用批量插入。 But, in my case I have an base class with some diferent subclasses represented by tables. 但是,就我而言,我有一个基类,其中某些不同的子类由表表示。 What is the best approach to handle this task? 处理此任务的最佳方法是什么?

Regards 问候

Camilo 卡米洛

如果您对buik插入没问题,仍然最简单的方法是构建一个小脚本,以使用适当的顺序构建表以实现参照完整性-在您的情况下,可能是产品,然后是产品实例(手机)。

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

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