【发布时间】:2016-07-28 10:19:51
【问题描述】:
现在我有一个小表 [dbo].[Model],它包括两列:id(int) 和 model(nvarchar(48))。
create table Model
(
id int primary key identity(1,1) not null,
model nvarchar(48)
)
表中大约有两千条记录,通常不需要插入新记录,除非找到新模型。
现在我有另一个表属性
create table Attribute
(
id bigint primary key identity(1,1) not null,
typeid int not null,--foreign key from another table
modelid int not null,--foreign key from [Model] table
attr nvarchar(max)
)
现在我应该在[Attribute]表中存储几百万行数据,首先我应该从[Model]表中获取模型id,由于[Model]表很小,如果我经常使用select语句来获取模型 id,我认为这不是一个好主意,因为它包括多重重复选择。
我想我可以只用一个select语句来生成像map这样的数据,当我得到一个模型时,我不需要再选择了,如果它已经存在于map数据中,直接使用它,否则,插入一个新的记录到 [Model] 表中。
以上解决方案是我的猜测,我不熟悉 sql server 或它的性能优化。我应该怎么做才能解决这个问题或者我应该学习什么样的知识?
谢谢。
【问题讨论】: